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]
# 1
a) Bind that part to a request beanb) There has to be someway you can know when a new request is being performed. There create a new date.c) Change the bean to request scope.d) ....
pringia at 2007-7-13 18:30:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

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

IamCowKinga at 2007-7-13 18:30:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
btw, this will work the same if GlobalsBean is in request or session scope.
IamCowKinga at 2007-7-13 18:30:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

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.

tony_robertsona at 2007-7-13 18:30:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...