1 Reply Latest reply on Jan 9, 2012 4:55 AM by Emir Calabuch

    s:convertDateTime not working in h:selectManyCheckbox

    AJ AJ Newbie

      I'm using JSF 1.2 with Seam and am trying to get a date formatted as dd/MM/yyyy within an h:selectManyCheckbox. The functionality of the h:selectManyCheckbox works fine in itself - it's just that it doesn't display the date correctly.

      <h:selectManyCheckbox id="paymentDates" value="#{entity.selectedPaymentDates}" layout="pageDirection" styleClass="radio">
           <s:convertDateTime type="date" dateStyle="short" pattern="dd/MM/yyyy"/>
           <s:selectItems value="#{entity.calculatedPaymentDates}" var="entity" label="#{entity}" hideNoSelection="true" />

      Any ideas greatfully appreciated!


        • 1. Re: s:convertDateTime not working in h:selectManyCheckbox
          Emir Calabuch Newbie

          You should not use a converter here: converters are intended to transform the data in the form to a backend representation (for example, convert a plain string captured in an text input field into a date, which is what <s:convertDateTime/> does).

          <h:selectManyCheckbox/> instead creates a checkbox input field for each selection item, so conversion is not what you want to do (the standard functionality should be ok for you). What you probably are trying to do is FORMAT the label for each of the checkboxes. This can be done using the label property of the <s:selectItems/> tag, like this:

          <h:selectManyCheckbox id="paymentDates" value="#{entity.selectedPaymentDates}" layout="pageDirection" styleClass="radio">
               <s:selectItems value="#{entity.calculatedPaymentDates}" var="date" label="#{convertDate.convert(date)}" />

          Note that there is no <s:convertDateTime/>. Sadly, to the best of my knowledge you cannot use a converter for each of the values in <s:selectItems/> so you need to do this manually inside a custom component (which I named convertDate):

          public class ConvertDate implements Serializable {
              // Inject the user's current locale
              @In private transient Locale locale;
               * This converts the date in the user's current locale format string
              public String convert(Date date) {
                  return DateFormat.getDateInstance(DateFormat.LONG, locale).format(date);