1

Running on my MacBook

  • JSF2.0
  • Primefaces 3.4.2
  • Eclipse Juno
  • Glassfish

When I run this code;

<h:form>
<h:outputText value="SMSC:" />

<p:selectCheckboxMenu id="graphsmscnames"
value="#{reportBean.selectedSmsclist}" label="SMSC" filter="true"
filterText="Filter" filterMatchMode="startsWith"
panelStyle="width:250px">

<f:selectItems value="#{reportBean.smsclist}" />

</p:selectCheckboxMenu>

<p:message for="graphsmscnames" />

<p:commandButton id="graphgenreport" value="Generate"
update=":reportpanel" action="#{reportBean.test}" />

</h:form>

and code in managedBean (with getters/setters for smsclist variable and selectedSmscList)

Map<String, String> smsclist;
private List<String> selectedSmsclist;

public constructure(){
smsclist=new HashMap<String,String>();
smsclist.put("one","one");
smsclist.put("two","two");
}

public void test(){
System.out.println(selectedSmsclist.size());
    }

Even when multiple/single items are selected from UI - it doesnt reflect inside my managedBean when commandButton is pressed. selectedSmscList List size is still zero.

2
  • What is the scope of your managed bean? The wrong scope will guarantee that your selectedSmcList will always be initialized to empty. Use @ViewScoped to be safe. Hint: it's unnecessary to override the constructor of your managed bean, use a @PostConstruct annotation on a method that will do the same job instead.
    – kolossus
    Nov 18, 2012 at 17:14
  • 1
    Its ViewScoped - really appreciate PostConstruct suggestion. It turns out that if I used multiple p:selectCheckboxMenu inside a single form, only one works and the other doesnt. So I worked out the UI to live with this for now because of time constraint. Appreciate your help.
    – khawarizmi
    Nov 20, 2012 at 0:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.