s:convertDateTime not working in h:selectManyCheckbox - jsf

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" />
</h:selectManyCheckbox>
Any ideas greatfully appreciated!
AJ

How is the date displayed?
you're using dateStyle with pattern. Use one or the other, not both. 'short" will format the date as:
5/14/07 12:55:42 PM
Though I think you'd have to use style="both" to get the time portion.
If you want to use a specific pattern try:
<s:convertDateTime type="date" pattern="dd/MM/yyyy"/>
or maybe:
<s:convertDateTime type="both" pattern="dd/MM/yyyy"/>

Related

ice:selectInputDate - valueChangeListener attribut not working when date entered manually

When I try to enter dates manually in tag that uses ice:selectInputDate, the valueChangeListener attribute doesnt work. When I click on the calendar symbol and select the date, the valueChangeListener works fine and my debug is redirected at proper method in bean.
Can anyone suggest on how to use valueChangeListener for this ice:selectInputDate when date is entered manually.
ValueChangeListener is not necessary
<ice:selectInputDate id="d1" renderMonthAsDropdown="true"
renderYearAsDropdown="true"
rendered="true"
renderAsPopup="true"
value="#{bean.myoDate}">
<f:convertDateTime pattern="dd/MM/yyyy"/>
</ice:selectInputDate>
make sure your panel/grid is enclosed with from
Try using ajax events as below
<ice:selectInputDate id="d1" renderMonthAsDropdown="true"
renderYearAsDropdown="true"
valueChangeListener ="#{yourbean.yourValueChangeListener}"
rendered="true"
renderAsPopup="true"
value="#{bean.myoDate}">
<f:convertDateTime pattern="dd/MM/yyyy"/>
<ace:ajax event="dateTextChange" execute="#this" />
<ace:ajax event="dateSelect" execute="#this" />
</ice:selectInputDate>

Triggering validation of <rich:calendar> client side?

I have a rich:calendar on a jsf page like this:
<rich:calendar id="someDate"
name="aName" validatorMessage="wrong format!"
enableManualInput="true" datePattern="dd/MM/yyyy"
value="#{MyBean.someDate}" >
</rich:calendar>
<rich:message id="validationSomeDate" for="someDate"
tooltip="false" showDetail="false">
<f:facet name="errorMarker">
<h:graphicImage id="imgError" value"/someImage.gif" />
</f:facet>
</rich:message>
<rich:tooltip for="validationSomeDate" value="wrong format!"/>
This succesfully validates that the user didn't write some nonsense into the date field like "12456" or something. The problem is, this validation is only triggered when the form is submitted. I would like to have this checked as soon as the date field loses focus, all client-side. Is there a way to do this?
I tried using a
<rich:validator>
tag but I'm using richfaces 3.x and this tag isn't available.
<rich:ajaxValidator event="onblur">
doesn't help either...

Format a JSF converted value

Today I noticed ocpsoft has a nice time library adapted to use in JSF 2 as a converter. The strong point of that is you can use the converter directly in the date displayed in the view and it converts it into a string telling the user something like 6 hours ago or 17 hours from now. I think my best is to combine both, the JSF converted date and this one to display something like 26-03-2013 17:00 (4 hours from now). I can achieve something similar with the following code:
<h:outputText value="#{task._StartDate}" style="padding:2px;">
<f:convertDateTime pattern="dd-MM-yyyy HH:mm" timeZone="GMT+1" />
</h:outputText>
<h:outputText value="#{task._StartDate}">
<f:converter converterId="org.ocpsoft.PrettyTimeConverter" />
</h:outputText>
My problem comes when I want to put the second value into parenthesis. The PrettyTimeConverter accepts only a date as a value and I can't write the parenthesis there directly. Also JSF is not accepting the following:
<h:outputFormat value="({0})">
<f:param value="#{task._StartDate}">
<f:converter converterId="org.ocpsoft.PrettyTimeConverter" />
</f:param>
</h:outputFormat>
With that I have the following error:
<f:converter> Parent not an instance of ValueHolder:
javax.faces.component.UIParameter#1492636
Any idea about how to achieve that avoiding writing both parentheses using specific h:outputText tags?
You can just put those parentheses directly in template text without the need for another <h:outputText>s.
<h:outputText value="#{task._StartDate}" style="padding:2px;">
<f:convertDateTime pattern="dd-MM-yyyy HH:mm" timeZone="GMT+1" />
</h:outputText>
(<h:outputText value="#{task._StartDate}">
<f:converter converterId="org.ocpsoft.PrettyTimeConverter" />
</h:outputText>)
See also:
Is it suggested to use h:outputText for everything?

JSF Selectitems Format Label Number

I've got a List of Numbers (range 500 - 5000, steps of 500).
I would like to add a decimal dot 1000 -> 1.000; 2500 -> 2.500 etc. but just for the labels not to be saved as a value.
I tried the following but it didnt work:
<h:selectOneMenu value="#{bean.selectedValue}">
<f:convertNumber type="currency" locale="de-DE" pattern="#,###" />
<f:selectItems itemValue="#{bean.selectItemslist}" var="item" itemLabel="#{item.label}" itemValue="#{item.value} />
</h:selectOneMenu>
But this didnt do anything :(
Tried several patterns and included integerOnly="true" but nothing seems to work :(
Thanks for your help!
The converter applies on the item value only, not on the item label. That explains why it "fails". In this particular case, your best bet is to create a custom EL function, so that you end up something like this:
<f:selectItems ... itemLabel="#{my:formatNumber(item.label, '#,###')}" />
The JSF utility library OmniFaces has several, see also OmniFaces functions/Numbers showcase.

How to bind a Date with calendar control in primefaces using binding attribute?

I want to bind a date with a calendar control after a specific value is selected from an autocomplete. But the following exception occurs :
javax.servlet.ServletException: java.util.Date cannot be cast to javax.faces.component.UIComponent
<p:autoComplete value="#{rechargeCustomerBean.school.schoolName}" completeMethod="#{rechargeCustomerBean.completeSchool}" required="true" />
<p:calendar mode="popup"
navigator="true" pattern="dd-MM-yyyy" effect="fadeIn"
showButtonPanel="true"
binding="#{rechargeCustomerBean.school.expiryDate}" />
Are you sure you want to bind?
Use the value attribute instead.
Also, add <p:ajax to your calendar to update the calendar and you are ready to go.
like this
<p:autoComplete value="#{rechargeCustomerBean.school.schoolName}" completeMethod="#{rechargeCustomerBean.completeSchool}" required="true">
<p:ajax event="itemSelect" update="idOfCalendar" />
</p:autoComplete>
Change
binding="#{rechargeCustomerBean.school.expiryDate}"
into
value="#{rechargeCustomerBean.school.expiryDate}"
so it will look like this
<p:calendar value="#{rechargeCustomerBean.school.expiryDate}" id="idOfCalendar"..... />
use of binding attribute in <p:calender> might cause the problem...try chaging it with value=#{...}
also make sure your bean's "expiryDate" is of type Util.Date
hope this could resolve your problem..for detailed explanation see here

Resources