Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This construct works fine for me.</p> <p>As mentioned in among others <a href="http://showcase.omnifaces.org/converters/SelectItemsConverter" rel="nofollow">the showcase page</a>, the <code>omnifaces.SelectItemsConverter</code> uses by default the <code>toString()</code> representation of the complex object as converted item value. So if you didn't override the <code>toString()</code> method (so that it still defaults to <code>com.example.SomeClass@hashcode</code> which changes on every instantiation) and the <code>#{item}</code> managed bean is request scoped, then the list would basically be changing on every HTTP request. This would cause a "Validation Error: Value is not valid" error. </p> <p>If you add</p> <pre><code>&lt;p:messages autoUpdate="true" /&gt; </code></pre> <p>or</p> <pre><code>&lt;p:growl autoUpdate="true" /&gt; </code></pre> <p>so that you get all (missing) validation/conversion messages in the UI, then you should have noticed it.</p> <p>In order to utilize the <code>omnifaces.SelectItemsConverter</code> at its best, you should override the <code>toString()</code> method accordingly so that it returns a fixed and unique representation of the complex object. E.g.</p> <pre><code>@Override public String toString() { return "Extra[id=" + id + "]"; } </code></pre> <p>Alternatively, you could put the <code>#{item}</code> managed bean in a broader scope, such as the view scope.</p> <hr> <p><strong>Update</strong> as to your update, you're binding the selected values of <em>all</em> checkboxgroups to <strong>one and same</strong> bean property <code>#{cartBean.selectedExtras}</code>. This way every iteration overrides the property with the values from the current iteration round as long as until you end up with the values of the last iteration. If you've placed a debug breakpoint on the setter, you'd have noticed that.</p> <p>This is not right. They should each point to a different bean property. Technically, you should have a <code>#{item.selectedExtras}</code> as property. But I think that this makes no sense in your current design. Better would be to make the <code>#{cartBean.selectedExtras}</code> an <code>List&lt;Item[]&gt;</code> or <code>Item[][]</code>. This way you can get them to set based on the iteration index as follows:</p> <pre><code>&lt;ui:repeat var="item" value="#{category.items}" varStatus="iteration"&gt; &lt;p:selectManyCheckbox id="extraCheckbox" value="#{cartBean.selectedExtras[iteration.index]}" layout="pageDirection" converter="omnifaces.SelectItemsConverter"&gt; &lt;f:selectItems value="#{item.items5}" var="extra" itemLabel="#{extra.name}"/&gt; &lt;/p:selectManyCheckbox&gt; &lt;/ui:repeat&gt; </code></pre> <p>In case of <code>List&lt;Item[]&gt;</code> you only need to make sure that you preinitialize <code>selectedExtras</code> with nulls as many times as there are <code>#{category.items}</code> in bean's (post)constructor.</p> <pre><code>for (Item item : category.getItems()) { selectedExtras.add(null); } </code></pre> <p>In case of <code>Item[][]</code>, you can suffice with </p> <pre><code>selectedExtras = new Item[category.getItems().size()]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload