JSF- SelectManyCheckBox cannot be add programmatically

683 Views Asked by At

I'm using primefaces 3.5 .

I have a HtmlPanelGrid to show a popup which contain a list of checkboxes. But the popup isnt show up.

private List<String> selectedList; 

public List<String> getSelectedList() {
    return selectedList;
}

public void setSelectedList(List<String> selectedList) {
    this.selectedList = selectedList;
}

public HtmlPanelGrid populateAccessesPanel() {
    final FacesContext facesContext = FacesContext.getCurrentInstance();
    final Application application = facesContext.getApplication();
    final ExpressionFactory expressionFactory = application
            .getExpressionFactory();
    final ELContext elContext = facesContext.getELContext();

    final HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application
            .createComponent(HtmlPanelGrid.COMPONENT_TYPE);


    final OutputLabel checkList = (OutputLabel) application
            .createComponent(OutputLabel.COMPONENT_TYPE);
    checkList.setFor("checkList");
    checkList.setId("checkListLabel");
    checkList.setValue("Check List");
    htmlPanelGrid.getChildren().add(checkList );


    final SelectManyMenu checkboxes =(SelectManyMenu) application
            .createComponent(SelectManyMenu.COMPONENT_TYPE);
    checkboxes.setId("checkList");
    checkboxes.setValueExpression
        ("value",expressionFactory.createValueExpression(elContext, "#{itemBean.selectedList}", String.class));
    checkbox.setRequired(false);


    SelectItem[] items = {
            new SelectItem(1, "Item 1"),
            new SelectItem(2, "Item 2"),
            new SelectItem(3, "Item 3"),
            new SelectItem(4, "Item 4"),
            new SelectItem(5, "Item 5")
        };

    UISelectItems selectItems = new UISelectItems();
    selectItems.setValue(cfaItems);

    checkboxes.getChildren().add(selectItems);



    htmlPanelGrid.getChildren().add(checkboxes);

    return htmlPanelGrid;
}

The actual result that i wish to get is like this:

<h:outputText value="Check List" />  
    <p:selectManyCheckbox value="#{itemBean.selectedList}"  
        layout="pageDirection">  
        <f:selectItems value="#{itemBean.selectItems}" />  
    </p:selectManyCheckbox>  

The code above isn't working when using "SelectManyCheckbox", but work fine if using "SelectBooleanCheckbox".

I also try for the "SelectManyMenu" and "SelectOneMenu", the result is same.

Since like the multiple selection component is not working with my code, do i miss up something ? It doesn't outcome any errors message for me to check with my code. I have been stuck with this problem for couples of days, and i cant find any solution from google.

Any help or ideas are greatly appreciated. Thank You.

0

There are 0 best solutions below