Search code examples
jsfjsf-2primefacesselectmanymenu

<p:selectManyMenu var> throws ELException: The class 'java.lang.String' does not have the property 'foo'


I am trying to implement primefaces selectManyMenu in advanced mode as shown in the showcase, however not able to get it work.

It works perfectly for selectOneMenu though.

Here is my code for selectOneMenu:

<p:selectOneMenu id="param" value="#{containerResultBean.selectedParam}"
                 converter="omnifaces.SelectItemsConverter" var="pa"
                 filter="true" filterMatchMode="contains" >
      <f:selectItem itemLabel="Select questions" itemValue="" />
      <f:selectItems value="#{containerResultBean.paramList}"
                     var="parameter" itemLabel="#{parameter.name}"
                     itemValue="#{parameter}"/>
      <p:column >
           <h:outputText styleClass="mediumFont" value="#{pa.name}"/>
           <h:outputText styleClass="mediumFont" value="#{pa.category.name}"/>
      </p:column>
</p:selectOneMenu>

for selectManyMenu

<p:selectManyMenu id="param" value="#{containerResultBean.selectedParamsList}"
                 converter="omnifaces.SelectItemsConverter" var="pa"
                 filter="true" filterMatchMode="contains" >
      <f:selectItem itemLabel="Select questions" itemValue="" />
      <f:selectItems value="#{containerResultBean.paramList}"
                     var="parameter" itemLabel="#{parameter.name}"
                     itemValue="#{parameter}"/>
      <p:column >
           <h:outputText styleClass="mediumFont" value="#{pa.name}"/>
           <h:outputText styleClass="mediumFont" value="#{pa.category.name}"/>
      </p:column>
</p:selectManyMenu>

I am getting an error value="#{pa.name}": The class 'java.lang.String' does not have the property 'name'.

I have doubled checked, my equal(), hashcode() and toString() methods. I think if there is problem with these methods then selectOneMenu also should not have worked.

Please note, when i remove the var='pa' and <column ...>, it works perfectly.


Solution

  • It's caused by the placeholder item which has an empty string as value.

    <f:selectItem itemLabel="Select questions" itemValue="" />
    

    Better explicitly make it #{null} instead of an empty string so it resolves to null instead of java.lang.String.

    <f:selectItem itemLabel="Select questions" itemValue="#{null}" />
    

    It worked in <p:selectOneMenu>, because its renderer simply renders the label when the item value is an instance of String (which would in turn thus fail if it's actually null; this is in turn likely an oversight/bug in PrimeFaces).

    See also: