You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Slattery, Tim - BLS" <Sl...@bls.gov> on 2004/09/08 21:39:39 UTC
Date format woes
I've got a page in my Struts web app that displays a date. It uses
<fmt:formatDate...> to read a date from the form bean and format it for
display. I also want to put that date into a <html:hidden...> field so that
it can be reloaded when the page is submitted and redisplayed.
The getter returns a Date. The <fmt:formatDate tag gets this and converts it
to the "default" format (Sep 9, 2005). No problem there. The
<html:hidden...> tag retrieves also retrieves it and converts it to this:
2005-09-09.
The getter returns a Date, the setter takes a String and converts it to a
Date. Or it tries to. I've put debug print into the setter, and it
apparently is not getting called at all! What's going on?
The app is running in Jboss 3.2.5
Here are my getter and setter pair:
/** setter for expirationDate
@param String new value for expirationDate
*/
public void setExpirationDate(String expirationDate)
{
System.out.println("New date: " + expirationDate);
try
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
this.expirationDate = sdf.parse(expirationDate);
}
catch (ParseException ex)
{
System.out.println("format failed: " + ex.getMessage());
this.expirationDate = null;
}
}
/** getter for expirationDate
@return Date value of expirationDate
*/
public Date getExpirationDate()
{
return expirationDate;
}
Here are the tags from the jsp page:
<strong>Expiration Date: </strong><fmt:formatDate
dateStyle="default"
value="${UpdPending.expirationDate}"/><BR>
<html-el:hidden property="expirationDate"/>
--
Tim Slattery
Slattery_T@bls.gov
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Date format woes
Posted by James Mitchell <jm...@apache.org>.
You wouldn't happen to have another setter method that accepts a different
type (e.g. Date) would you?
for example:
...
...
public void setExpirationDate(Date expirationDate){
...
...
--
James Mitchell
Software Engineer / Open Source Evangelist
EdgeTech, Inc.
678.910.8017
AIM: jmitchtx
----- Original Message -----
From: "Slattery, Tim - BLS" <Sl...@bls.gov>
To: <st...@jakarta.apache.org>
Sent: Wednesday, September 08, 2004 3:39 PM
Subject: Date format woes
> I've got a page in my Struts web app that displays a date. It uses
> <fmt:formatDate...> to read a date from the form bean and format it for
> display. I also want to put that date into a <html:hidden...> field so
that
> it can be reloaded when the page is submitted and redisplayed.
>
> The getter returns a Date. The <fmt:formatDate tag gets this and converts
it
> to the "default" format (Sep 9, 2005). No problem there. The
> <html:hidden...> tag retrieves also retrieves it and converts it to this:
> 2005-09-09.
>
> The getter returns a Date, the setter takes a String and converts it to a
> Date. Or it tries to. I've put debug print into the setter, and it
> apparently is not getting called at all! What's going on?
>
> The app is running in Jboss 3.2.5
>
> Here are my getter and setter pair:
>
> /** setter for expirationDate
> @param String new value for expirationDate
> */
> public void setExpirationDate(String expirationDate)
> {
> System.out.println("New date: " + expirationDate);
> try
> {
> SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
> this.expirationDate = sdf.parse(expirationDate);
> }
> catch (ParseException ex)
> {
> System.out.println("format failed: " + ex.getMessage());
> this.expirationDate = null;
> }
> }
>
> /** getter for expirationDate
> @return Date value of expirationDate
> */
> public Date getExpirationDate()
> {
> return expirationDate;
> }
>
> Here are the tags from the jsp page:
>
> <strong>Expiration Date: </strong><fmt:formatDate
> dateStyle="default"
> value="${UpdPending.expirationDate}"/><BR>
> <html-el:hidden property="expirationDate"/>
>
>
> --
> Tim Slattery
> Slattery_T@bls.gov
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org