File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting DATE field on the fly

 
Shanmugam Muthukumarasamy
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a requirement to format the date field on the fly. For example, if I am entering a date in the <html:text> field as 02/20/2006, the slashes (/) should be added automatically, when I finish entering 02 and 20.

I mean, the user is not pressing the '/' key at all, It has to be added when I finish the MM and DD fields.

I was thinking of using JSTL for this. But I don't know how and where to start....

Your help would be greatly appreciated !!!

Thanks in advance,
Shanmugam
 
Brent Sterling
Ranch Hand
Posts: 948
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm...I don't see where JSTL or Struts tags will help you with this. It seems like this will have to be done using client side JavaScript. I have never implemented something like this but I would not be surprised if a search of these forums or the Internet on "format date javascript" turned up some examples.

- Brent
 
Shanmugam Muthukumarasamy
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Brent,

When I try to use this Javascript,
It is not accepting the <bean:write> as parameter
<label><bean:message key="insuredInfo.effDate" />:</label>
<html:text property="effectiveDate" on key press='javascript:fDate(<bean:write name="insuredInfoFormBean" property="effectiveDate"/> '/>
<span CLASS="errormessage">
<html:errors property='effectiveDate' />
</span><br>

If I don't send the parameter using <bean:write> the Javascript function is working.

Thanks,
Shanmugam
[ February 20, 2006: Message edited by: Shanmugam Muthukumarasamy ]
 
Shanmugam Muthukumarasamy
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<label><bean:message key="insuredInfo.effDate" />:</label>
<html:text property="effectiveDate" on key press='javascript:fDate(<bean:write name="insuredInfoFormBean" property="effectiveDate"/> '/>
<span CLASS="errormessage">
<html:errors property='effectiveDate' />
</span><br>

because of javaranch restriction, I had given space between the property on key press
[ February 20, 2006: Message edited by: Shanmugam Muthukumarasamy ]
 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 - you can't nest custom tags as attributes to other custom tags.
2 - when you press a key, it won't invoke the bean:write tag.

Java/JSP runs on server side, and produces an html page, which it sends to the browser.
Then you can start running javascript (and reacting to javascript events)
You only run java again when you make a request (submit a form, click a link etc)
Basically you have to do this date formatting/validation in pure html/javascript.

Instead of passing the value, I would recommend passing the textfield itself using the "this" keyword.

 
Shanmugam Muthukumarasamy
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan Evans !!! This worked for me !!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic