0

I am trying to use

Map<String,String> 

style selectItems in my

<p:selectCheckboxMenu> 

but unfortunately, it not works.

Backing bean:

@Named(value = "roleBean")
@SessionScoped
public class RoleBean(){
  private Map<String,String> roleMap;
  private String[] selectRoles;
  ......
  ......
  public void findRoleMap(){
    if(roles.size()>0){
      for(Role r:roles){
        roleMap.put(r.getRoleId(),r.getRoleName());
      }
    logger.info("Role Map size: " + roleMap.size());
    }
  }
}

jsf as:

<p:selectCheckboxMenu id="roles" value="#{roleBean.selectRoles}" label="Select your roles" filter="true" filterMatchMode="startsWith" height="200" panelStyle="width:200px">
   <f:selectItems value="#{roleBean.roleMap.entrySet}" var="entry" itemLabel="#{entry.value}" itemValue="#{entry.key}"/>
</p:selectCheckboxMenu>

When I access the page, I found there is 6 records were added into the map. but unfortunately, there is nothing shows up in the selectCheckboxMenu drop down list.

If I change the UIComponent to

<p:selectOneMenu> 

from

<p:selectCheckboxMenu>

it shows up properly in dropdown list.

I tried to find out through google, I didn't find anyone else trying to use key/value pair in Map style as selectItems in selectCheckboxMenu. I was very confused.

My question is: Does selectCheckboxMenu support key/value pair mapping style or not, if it does. How To do it?

Please advise!!

cidy.long
  • 417
  • 12
  • 35
  • _"Please advise!!"_ Try 5.3 or 6.0 first. Regarding 'supporting it', you can check the source (it is open) And did you try `Map`? – Kukeltje Dec 15 '16 at 10:09
  • Thank you for you advice. Unfortunately. I am using webLogic 12cR2, it only support JSF 2.2 and primeFaces 5.2. Other version primeFaces not tested. Maybe will have some unknown error. – cidy.long Dec 15 '16 at 10:26
  • Uhhh... Weblogic 12cR2 should run PrimeFaces 5.3 or 6.0 as well. No reason it should not – Kukeltje Dec 15 '16 at 10:34

1 Answers1

0
<f:selectItems value="#{bean.map.entrySet()}" var="entry" 
    itemLabel="#{entry.key}" itemValue="#{entry.value}" />
zforgo
  • 2,508
  • 2
  • 14
  • 22
coder
  • 1