Search code examples
jsf-1.2renderer

How to read bean value within Renderer


I am writing a custom jsf Renderer for checkboxes and radio buttons to render without TABLE element. My question is if I have a select box like below

    <h:selectManyCheckbox id="vehicle" value="#{pageBean.vehicle}>
       <f:selectItems value="#{pageBean.vehiclesList} />
    </h:selectManyCheckbox>

in the encodeBegin method how can I read the vehiclesList?


Solution

  • It was straight forward.

    Iterator<UIComponent> iterator = component.getFacetsAndChildren();
    
    while (iterator.hasNext()) {
        UIComponent childComponent = iterator.next();
        List vehicles = childComponent.getValueExpression("value").getValue(context.getELContext);
        // Do whatever with vehicles.
    }
    

    Here I assumed that there is only one child to the main component which is SelectItems.