PrimeFaces 5.2 selectCheckboxMenu not support Map<String,String> style selectItems

607 Views Asked by At

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!!

1

There are 1 best solutions below

0
coder On
<f:selectItems value="#{bean.map.entrySet()}" var="entry" 
    itemLabel="#{entry.key}" itemValue="#{entry.value}" />