Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The value which is passed through the converter is not the option label as you seem to expect, but the option value. The best practice is to not do this in the model side, but in the view side, because the model shouldn't need to be i18n aware.</p> <p>As to the approach, you're basically unnecessarily overcomplicating things. Since JSF 1.2 there's a builtin <a href="http://download.oracle.com/javaee/6/api/javax/faces/convert/EnumConverter.html" rel="noreferrer"><code>EnumConverter</code></a> which will kick in automatically and since JSF 2.0 you can iterate over a generic array or <code>List</code> in <code>f:selectItems</code> by the new <code>var</code> attribute without the need to duplicate the values over a <code>List&lt;SelectItem&gt;</code> in the model.</p> <p>Here's how the bean can look like:</p> <pre><code>public class Bean { private OrderStatus orderStatus; private OrderStatus[] orderStatuses = OrderStatus.values(); // ... } </code></pre> <p>And here's how the view can look like (assuming that <code>msg</code> refers to the <code>&lt;var&gt;</code> as you've definied in <code>&lt;resource-bundle&gt;</code> in <code>faces-config.xml</code>):</p> <pre><code>&lt;h:selectOneMenu value="#{bean.orderStatus}"&gt; &lt;f:selectItems value="#{bean.orderStatuses}" var="orderStatus" itemValue="#{orderStatus}" itemLabel="#{msg[orderStatus.name]}" /&gt; &lt;/h:selectOneMenu&gt; </code></pre> <p>That's all.</p> <hr> <p>Unrelated to the problem, you've typos in the enum name and message keys, it should be:</p> <pre><code>PENDING("enum.orderstatus.pending"), CANCELLED("enum.orderstatus.cancelled"); </code></pre> <p>And, more clean would be to keep the bundle keys out the enum and use enum itself as part of bundle key. E.g.</p> <pre><code>PENDING, CANCELLED; </code></pre> <pre class="lang-html prettyprint-override"><code>&lt;h:selectOneMenu value="#{bean.orderStatus}"&gt; &lt;f:selectItems value="#{bean.orderStatuses}" var="orderStatus" itemValue="#{orderStatus}" itemLabel="#{msg['enum.orderstatus.' += orderStatus]}" /&gt; &lt;/h:selectOneMenu&gt; </code></pre> <pre class="lang-none prettyprint-override"><code>enum.orderstatus.PENDING = Pending enum.orderstatus.CANCELLED = Cancelled </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.
    3. VO
      singulars
      1. This table or related slice is empty.
    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