2

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ankit
  • 1,075
  • 1
  • 8
  • 19
  • Is `containerResultBean.selectedParamsList` a *list* object? It seems `pa` is taken like a String object. – Miguel Jul 06 '15 at 09:13
  • @Miguel yes, selectedParamsList is a list object. `private List selectedParamsList = new ArrayList<>();` – Ankit Jul 06 '15 at 10:25
  • @Miguel i dont understand why it is taken as a String object in ManyMenu and not in OneMenu? – Ankit Jul 06 '15 at 10:26
  • I'm not familiarized with Omnifaces but perhaps the problem is the converter. Sorry, I don't know Omnifaces and I can help you more. I'll be close for helping you with other possible issue. – Miguel Jul 06 '15 at 11:57
  • 1
    @Miguel thanks, but Omnifaces converter is using toString method of the class and is similar to what one implements by his own. Converter is simply converting the Entity object to String and from String, back to Entity. Therefore if there is a problem with converter than OneMenu should not work too. This is what my understanding about converters is.. – Ankit Jul 06 '15 at 12:43
  • 2
    Moreover, the converter only applies to ``, not to the customized representation. – BalusC Jul 06 '15 at 12:56

1 Answers1

2

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555