Date Formatting with 2 vs 4 Year Dates

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Date Formatting with 2 vs 4 Year Dates

Matt White-4
Hi Y'all -

Here's something I keep on struggling with, so I'm sure I'm doing
something weird.

In my ActionBean I have:

@Validate(required = true)
private Date startDate = null;

(...and then getters/setters for this field)

In my JSP I have this:

<s:text class="input-small" type="text" name="startDate"
placeholder="MM/DD/YYYY"/>


Here's the deal. When the page is displayed, the date shows up in the
field in the format MM/DD/YY, but the validator wants MM/DD/YYYY. (After
having be around in the Y2k era, I do too.) Every time I go to pull up a
form with a date in it it is displayed with the two digit date, but I
have to manually go back and change it to a four digit date to get the
Validator to accept it.

ie, I click on "edit", the form is pre-populated in the default handler
in the ActionBean, the JSP displays it with a two digit year, but then
in order to save my changes I have to make the changes I wanted to
change *AND* then go set the date to a four digit date each and every
round trip to the server.

What am I doing wrong?

I'm using Stripes 1.5.7 on Tomcat 7.0.34.

Thanks!!

- Matt

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Date Formatting with 2 vs 4 Year Dates

Matt White-4
On 12/26/2012 6:40 PM, Matt White wrote:
> <s:text class="input-small" type="text" name="startDate"
> placeholder="MM/DD/YYYY"/>

Gah. I sweat this out for an hour, post something on the mailing list,
and then figure it out on my own a few minutes later.

Just to close the loop on this, you need to set the formatType to "date"
so that Stripes knows you're working with date data. That line above
should read like this:

<s:text class="input-small" type="text" name="startDate"
formatType="date" formatPattern="M/d/yyyy" placeholder="MM/DD/YYYY"/>

- Matt

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Date Formatting with 2 vs 4 Year Dates

Freddy D.
Hi Matt,

> Gah. I sweat this out for an hour, post something on the mailing list,
> and then figure it out on my own a few minutes later.

That's quite alright--score another one for the Rubber Duck:
http://en.wikipedia.org/wiki/Rubber_duck_debugging

Cheers,
Freddy

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Date Formatting with 2 vs 4 Year Dates

Matt White-4
On 12/26/2012 10:09 PM, Freddy Daoud wrote:
> That's quite alright--score another one for the Rubber Duck:
> http://en.wikipedia.org/wiki/Rubber_duck_debugging

Freddy -

When I was in college I had a TA that left a Teddy Bear on his desk
during labs. Before you could ask him a question you had to ask the
Teddy Bear out loud first.

It was amazing how smart that bear was. :)

- Matt

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users