That's neato. I can specify the locale in the link to this special page/action & thereby get my date to parse!
Thanks! Dan > -----Original Message----- > From: Rene Gielen [mailto:gie...@it-neering.net] > Sent: Wednesday, March 31, 2010 6:21 AM > To: Struts Users Mailing List > Subject: Re: textfield with Date object > > Hi, > > (copied from an earlier thread on numbers) > > see > http://struts.apache.org/2.1.8.1/docs/formatting-dates-and-numbers.html > > It is important to know that Struts 2 has always a locale context > request for each request, which affects both formating and parsing > dates > and numbers. The request locale is determined as follows: > > 1. Request parameter > (http://struts.apache.org/2.1.8/docs/i18n-interceptor.html) > 2. Session attribute > (http://struts.apache.org/2.1.8/docs/i18n-interceptor.html) > 3. Browser preference > 4. Server side JVM default > > The first matching lookup wins. > > The type conversion mechanism tries to parse dates and numbers in the > current locale context, thus you should be fine when you ensure that > you > have a consistent locale request setting both for the first request > (rendering the form and the current value in the textfield) and the > second request (processing the submitted form). > > - René > > Wick, Dan schrieb: > > I accept your answer, but Struts2 should just handle this! :-( > > > > I guess I'll write a number of helper methods like you did. > > > >> -----Original Message----- > >> From: Greg Lindholm [mailto:greg.lindh...@gmail.com] > >> Sent: Tuesday, March 30, 2010 10:14 AM > >> To: Struts Users Mailing List > >> Subject: Re: textfield with Date object > >> > >> (Seems like I just answered this question... but here it is again > this > >> time for Dates) > >> > >> In my experience it's better to define number (and time) input > fields > >> as String and perform the conversion and validation in your action > >> using java.text.NumberFormat (and java.text.DateFormat). This puts > >> you in control of the > >> process and let's you handle I18N issues that way you want to > without > >> fighting Struts. > >> > >> I typically have a couple of helper methods I put into the base > Action > >> class that simplify getting the users Locale and DateFormat. > >> Depending on the app the users Locale may come from a Login object > or > >> the browser request (which Struts can retrieve) or from a cookie. > >> > >> On Tue, Mar 30, 2010 at 10:34 AM, Wick, Dan > <daniel.w...@donaldson.com> > >> wrote: > >>> Does anyone know how to change the format of dates coming in on a > >> text input being backed by a java.util.Date in the Action? If I > enter > >> dates in US format (ex: 3/31/2010 for March 31, 2010) everything is > >> fine. This requires a different style input though, using > >> Day/Month/Year (31/3/2010). I suppose I could take in a string & > parse > >> it for a date myself, but I'm wondering if there's a Right way to do > >> it. > >>> --Dan > >>> > >>> <-- Snip of jsp page --> > >>> Date Of Birth* > >>> <s:textfield name="dob" required="true" tabindex="4" size="30" > >> cssClass="staticBody" cssErrorClass="formError"/> > >>> <-- End snip of jsp page --> > >>> > >>> > >>> <-- Snip of Action --> > >>> > >>> private Date dob; > >>> public Date getDob() { > >>> return dob; > >>> } > >>> @RequiredStringValidator(message="Date of Birth is > required.", > >> trim=true) > >>> public void setDob(Date dob) { > >>> this.dob = dob; > >>> } > >>> <-- End snip of Action --> > >>> > >>> > >>> > >>> ------------------------------------------------------------------- > -- > >>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > >>> For additional commands, e-mail: user-h...@struts.apache.org > >>> > >>> > >> -------------------------------------------------------------------- > - > >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > >> For additional commands, e-mail: user-h...@struts.apache.org > >> > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > > > -- > René Gielen > IT-Neering.net > Saarstrasse 100, 52062 Aachen, Germany > Tel: +49-(0)241-4010770 > Fax: +49-(0)241-4010771 > Cel: +49-(0)163-2844164 > http://twitter.com/rgielen > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org