0

I need to create a custom component that either extend or include a Primefaces SelectOneMenu. This is done so that I can deliver the select items based on the field (for now, they are hardcoded in the example below and the tag is properly registered).

The component is rendered and the select items are also displayed fine. However, when I save, the record's field is not updated with the selected item's value. Is there some primeface method I should override to actually set the value?

Are there any tutorials on how to extend primeface (or atleast jsf) components? I could hardly find any. Thank you in advance

@FacesComponent(value = ComponentRegistry.INPUT_SELECTDROPDOWN_COMPONENT_TYPE)
public class InputSelectDropdown extends SelectOneMenu {

    @Override
    public void encodeBegin(FacesContext context) throws IOException {

        this.setValueExpression("value", this.getValueExpression("value"));

        UISelectItem select1    =   new UISelectItem();
        select1.setItemLabel("item 1");
        select1.setItemValue("item1");
        select1.encodeAll(context);
        this.getChildren().add(select1);

        UISelectItem select2    =   new UISelectItem();
        select2.setItemLabel("item 2");
        select2.setItemValue("item2");
        select2.encodeAll(context);
        this.getChildren().add(select2);        

        super.encodeBegin(context);
    }    
}
  • 2
    why do you need to create a custom component? Most cases can be solved only with a converter – Javier Oct 22 '18 at 06:58
  • Because I want to populate the select options across the application from the component itself ( depending on the entity field). Also to try it, how to write a custom component. – Cadrian Brown Oct 22 '18 at 07:42
  • 1
    Why not use a composite component for this? Way easier... https://stackoverflow.com/questions/12847003/whats-the-difference-between-jsf-custom-composite-components-vs-custom-classic-c. And effectively, (many of the) the PrimeFaces components are 'custom' components in the sense that the extend the basic jsf components. So they are a good example how to write a custom component. – Kukeltje Oct 22 '18 at 08:41

0 Answers0