How can I return different values in a FormComponent method?

31 Views Asked by At

I have this method that is going to create 2 textfields and a combobox. But I have a problem returning the different values because it gives me an error that "Type mismatch: cannot convert from ComboCustom to FormComponent<?>"

The 2 textfields work great, but I don´t understand why the combobox doesn´t and how to make it work. Thanks in advance.

    private static FormComponent<?>[] criaComponentes(FiltroListaEquipamentosASerSubstituido2 filtro) {
        
        
        ComboCustom<EqpMarca> marca = new ComboCustom<EqpMarca>("marca", new PropertyModel<EqpMarca>(filtro, "marca"), list, new ChoiceRenderer<EqpMarca>() {
            private static final long serialVersionUID = 1L;

            @Override
            public String getDisplayValue(EqpMarca est) {
                return est.getDesignacao();
            }

            @Override
            public String getIdValue(EqpMarca est, int arg) {
                return String.valueOf(est.getIdMarca());
            }
        });
        
        
        marca.add(new AjaxFormComponentUpdatingBehavior(HtmlTag.ONCHANGE) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                target.add(marca);
            }
        });
        
        return new FormComponent<?>[] {
            new TextField<String>("nome", new PropertyModel<String>(filtro, "nome")),
            marca,
            new TextField<String>("modelo", new PropertyModel<String>(filtro, "modelo"))
        };
        
    }
1

There are 1 best solutions below

2
martin-g On

ComboCustom seems to be an implementation of IChoiceRenderer. It is not really a FormComponent