Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use omnifaces coalesce to turn nulls into a number, for use in ChoiceFormat
    primarykey
    data
    text
    <p>I currently have the following JSF: </p> <pre><code>&lt;p:outputLabel value="#{msg['label.address.province']}" rendered="#{address.country ne CountryEnum.UNITED_STATES.country}"/&gt; &lt;p:outputLabel value="#{msg['label.address.province']}" rendered="#{address.country eq CountryEnum.UNITED_STATES.country}"/&gt; </code></pre> <p>And my properties file contains</p> <pre><code>label.address.province=Province label.address.state=State </code></pre> <p>This works fine, and when the country is "US", my label outputs "State", and for any other country, it outputs "Province". </p> <p>What I had thought to do, is try to get rid of the two label entries and just use one, with a choiceformat in the messages.properties. My first try looked like: </p> <pre><code>&lt;h:outputFormat value="#{msg['label.address.province.choice']}"&gt; &lt;f:param value="#{address.country.id}"/&gt; &lt;/h:outputFormat&gt; </code></pre> <p>with</p> <pre><code>label.address.province.choice={0, choice, 1#Province|2#State|3#Province} </code></pre> <p>Which worked fine, when editing an address. But when adding a new address, by my business rules, all fields are blank. Which means address.country is null, which means my choiceformat produces 'null' as output. </p> <p>Then I thought to use omnifaces: </p> <pre><code>&lt;h:outputFormat value="#{msg['label.address.province.choice']}"&gt; &lt;f:param value="#{o.coalesce(address.country.id, '1')}"/&gt; &lt;/h:outputFormat&gt; </code></pre> <p>But this also produces null. address is my managed bean, country is my own simple javabean class, id is a property of type <code>java.io.Serializable</code>. </p> <p>I know that "address.country.id" is evaluated by EL and it "nicely" stops when it encounters null and doesn't throw an NPE. But, is it perhaps that coalesce doesn't do this same type of behaviour, and what I pass in must be a non-EL expression? Sorry, I'm just beginning my JSF adventure so I'm probably not using the right words. </p> <p>I'm also open to just taking a totally different approach, which still reduces my outputLabels to a single label of some type. </p> <p>I'm using Mojarra 2.1.21, Primefaces 3.5, Omnifaces 1.4.1, Java 7, Tomcat 7</p>
    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.
 

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