Differences between revisions 3 and 4
Revision 3 as of 2006-05-09 21:56:26
Size: 1432
Revision 4 as of 2009-09-20 23:00:41
Size: 1432
Editor: localhost
Comment: converted to 1.6 markup
No differences found!


It is often necessary to display a Boolean (true/false) on a web page using custom Strings to represent the true and false values. For example, you might want to display "Yes" instead of "true" and "No" instead of "false".

This <s:convertBoolean> tag, which uses the BooleanConverter internally, can be used to accomplish such formatting. Its usage is analagous to the use of <f:convertDateTime> to format a java.util.Date.


<h:outputText value="#{backingBean.customer.enjoysJazz}">
    <s:convertBoolean trueValue="Yes" falseValue="No"/>

You can also use a managed bean for the Yes and No values

<h:outputText value="#{backingBean.customer.enjoysJazz}">
    <s:convertBoolean trueValue="#{Message.Yes}" falseValue="#Message.No"/>

Also, it might be quite useful to use it inside a selectOneRadio, example:

<h:selectOneRadio value="#{backingBean.customer.enjoysJazz}">
   <f:selectItem itemLabel="#{Message.Yes}" itemValue="1" />
   <f:selectItem itemLabel="#{Message.No}" itemValue="0" />
   <s:convertBoolean trueValue="1" falseValue="0"/>

and in the managed bean...

class Customer

  private Boolean enjoysJazz;
  // getters and setters here

The "backingBean.customer.enjoysJazz" value binding expression above represents a java.lang.Boolean value.

ConvertBoolean (last edited 2009-09-20 23:00:41 by localhost)