Displaying Date in output Text
Hi,
I got stuck up with a small problem. I have a Purchase Order form in which i need to show the system date dynamically when my page gets load. I am using Rational Application developer, since binding a session bean doesn't work as at form load no session bean will be created.
Please suggest me a solution for this.
Thanks in Adv.
Regards,
Mak
[389 byte] By [
tiger_maka] at [2007-10-2 17:14:58]

I do it this way:
<h:outputText id="date"
value="#{globalsBean.date}" styleClass="bodyText">
<f:convertDateTime type="date" pattern="MMM dd, yyyy" />
</h:outputText>
The GlobalsBean.getDate() method returns a new instance of java.util.Date.
/**
* Get the current Date. Returns as a <code>java.util.Date</code>.
*
* @return
*/
public Date getDate() {
return new Date();
}
CowKing
It doesn't have to be that complicated. Just define a request scope managed bean like this:
<managed-bean>
<description>Current Timestamp</description>
<managed-bean-name>now</managed-bean-name>
<managed-bean-class>java.util.Date</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Then reference it where you need it, like this:
<h:outputText id="date" value="#{now}" styleClass="smallDate">
<f:convertDateTime type="date" pattern="dd/MM/yyyy hh:mm:ss" />
</h:outputText>
Because it is request-scope, a new instance will be generated with each request.