You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Celinio Fernandes <ce...@yahoo.com> on 2009/11/15 23:08:20 UTC
[Struts 2.1.8] datetimepicker and action: String or Date ??
Hi,
I have struts2-core-2.1.8.jar and xwork-core-2.1.6.jar in my classpath.
I read that there are many problems of conversion using the datetimepicker tag.
I checked the vault page here :
http://cwiki.apache.org/S2WIKI/troubleshooting-guide-migrating-from-struts-20x-to-21x.html#TroubleshootingguidemigratingfromStruts2.0.xto2.1.x-Userdefinedconverter%2528subclassingStrutsTypeConverter%2529willnolongerbeneededwhenusingdatetimepicker%253A
But what exactly is the type of the getter/setter in the action ??
For instance if I use this line in a JSP :
<sx:datetimepicker name="expirationDate" key=".dateexpiMois" displayFormat="MM/yyyy" required="true"/>
What getters should i get in my action ?
java.util.Date expirationDate;
//String expirationDate;
public java.util.Date getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(java.util.Date expirationDate) {
this.expirationDate = expirationDate;
}
==> I get this error :
java.lang.NoSuchMethodException: com.eni.dvtejb.clientStruts2.action.PaiementAction.setExpirationDate([Ljava.lang.String;)
And if i use getter/setter of type String, it complains about some RFC format that is not valid.
So how exactly does it work ? Can someone provide a good example with the code for the action and the code for the JSP with the datetimepicker tag ?
Thanks.
RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
> I skipped it because I cannot figure out the format to handle
> that colon in the middle of that time zone.
The only solution I found was to manually take it out of the
date string.
Neil
--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net
Host your struts app on a CentOS VPS for only $25/month!
Unmetered bandwidth, 7 day no risk trial, Google Checkout
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Fernandes Celinio <cf...@sopragroup.com>.
I skipped it because I cannot figure out the format to handle that colon in the middle of that time zone.
I tried without that time zone and saw that it works anyways.
Thanks again.
-----Message d'origine-----
De : Neil Aggarwal [mailto:neil@JAMMConsulting.com]
Envoyé : lundi 16 novembre 2009 17:18
À : 'Struts Users Mailing List'
Objet : RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
> That was a good lead. Thanks.
> SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
> So I got it working now but that was a pain.
I am glad you found the suggestion useful and were able to get it working.
I see you skipped the time zone in your format.
That is another pain, the DateFormat class does not like a colon in the middle of the time zone either. I assume you are not using multiple time zones so you should be OK.
Neil
--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net Host your struts app on a CentOS VPS for only $25/month!
Unmetered bandwidth, 7 day no risk trial, Google Checkout
---------------------------------------------------------------------
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
RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
> That was a good lead. Thanks.
> SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
> So I got it working now but that was a pain.
I am glad you found the suggestion useful and were
able to get it working.
I see you skipped the time zone in your format.
That is another pain, the DateFormat class
does not like a colon in the middle of the time
zone either. I assume you are not using multiple
time zones so you should be OK.
Neil
--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net
Host your struts app on a CentOS VPS for only $25/month!
Unmetered bandwidth, 7 day no risk trial, Google Checkout
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Fernandes Celinio <cf...@sopragroup.com>.
Hi Neil,
That was a good lead. Thanks.
I used this format :
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
I checked the source of the DateTimePicker class to get the correct format.
So I got it working now but that was a pain.
-----Message d'origine-----
De : Neil Aggarwal [mailto:neil@JAMMConsulting.com]
Envoyé : lundi 16 novembre 2009 15:48
À : 'Struts Users Mailing List'
Objet : RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Fernandes:
> java.text.ParseException: Unparseable date:
> "2009-11-20T00:00:00+01:00"
> java.text.DateFormat.parse(Unknown Source)
I have seen this behavior before.
The date format you have is an ISO format, but the Java DateFormat class does not parse dates in that format.
I think you will need to manually pull the date out of the request params and format it to something DateFormat understands.
Something like this:
2009-11-20 00:00:00 +0100
Here is a sample code:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ZZZZZ");
Date date = dateFormat.parse("2009-11-20 00:00:00 +0100");
System.out.println(DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.LONG).format(date));
I hope this helps,
Neil
--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net CentOS 5.4 VPS with unmetered bandwidth only $25/month!
7 day no risk trial, Google Checkout accepted
---------------------------------------------------------------------
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
RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
Fernandes:
> java.text.ParseException: Unparseable date:
> "2009-11-20T00:00:00+01:00"
> java.text.DateFormat.parse(Unknown Source)
I have seen this behavior before.
The date format you have is an ISO format, but
the Java DateFormat class does not parse dates
in that format.
I think you will need to manually pull the
date out of the request params and format
it to something DateFormat understands.
Something like this:
2009-11-20 00:00:00 +0100
Here is a sample code:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss
ZZZZZ");
Date date = dateFormat.parse("2009-11-20 00:00:00 +0100");
System.out.println(DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.LONG).format(date));
I hope this helps,
Neil
--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net
CentOS 5.4 VPS with unmetered bandwidth only $25/month!
7 day no risk trial, Google Checkout accepted
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Fernandes Celinio <cf...@sopragroup.com>.
Well, thanks for helping.
I am going to switch to a simple textfield tag if datetimepicker is so messy regarding date format and conversion.
Anyways here is the source code again :
---------------- In my JSP (I choose MM/yyyy. It returns a Strign with this format : 2009-11-24T00:00:00+01:00 ) ----------------
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
...
<sx:datetimepicker name="expirationDate" key="paiement.dateexpiMois" displayFormat="MM/yyyy" required="true"/>
---------------- In my Action (Notice that I choose a String type for the getter/setter) ----------------
String expirationDate;
public String getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}
// This method expects a String Date with the format MM/yyyy (but I know it receives a different format : 2009-11-24T00:00:00+01:00)
public static Date stringToDate(String sDate) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("MM/yyyy");
return formatter.parse(sDate);
}
public String blabla() throws Exception {
java.util.Date utilDate = stringToDate(getExpirationDate());
System.out.println(" ------------ utilDate : " + utilDate);
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
System.out.println(" ------------ sqlDate : " + sqlDate);
othermethod(sqlDate);
}
---------------- Stack trace (The date I choose is : 11/2009): ----------------
java.text.ParseException: Unparseable date: "2009-11-24T00:00:00+01:00"
java.text.DateFormat.parse(Unknown Source)
com.eni.dvtejb.clientStruts2.action.PaiementAction.stringToDate(PaiementAction.java:197)
com.eni.dvtejb.clientStruts2.action.PaiementAction.payer(PaiementAction.java:173)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
Any idea ? thanks
-----Message d'origine-----
De : Lukasz Lenart [mailto:lukasz.lenart@googlemail.com]
Envoyé : lundi 16 novembre 2009 10:50
À : Struts Users Mailing List
Objet : Re: [Struts 2.1.8] datetimepicker and action: String or Date ??
2009/11/16 Fernandes Celinio <cf...@sopragroup.com>:
> This is what I get :
> java.text.ParseException: Unparseable date: "2009-11-20T00:00:00+01:00"
> java.text.DateFormat.parse(Unknown Source)
Could you show the whole stack?
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
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
Re: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/11/16 Fernandes Celinio <cf...@sopragroup.com>:
> This is what I get :
> java.text.ParseException: Unparseable date: "2009-11-20T00:00:00+01:00"
> java.text.DateFormat.parse(Unknown Source)
Could you show the whole stack?
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Fernandes Celinio <cf...@sopragroup.com>.
This is what I get :
java.text.ParseException: Unparseable date: "2009-11-20T00:00:00+01:00"
java.text.DateFormat.parse(Unknown Source)
-----Message d'origine-----
De : Fernandes Celinio [mailto:cfernandes@sopragroup.com]
Envoyé : lundi 16 novembre 2009 10:40
À : Struts Users Mailing List
Objet : RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Any advice, please ?
Thanks.
-----Message d'origine-----
De : Celinio Fernandes [mailto:cel975@yahoo.com] Envoyé : dimanche 15 novembre 2009 23:08 À : Struts Users Mailing List Objet : [Struts 2.1.8] datetimepicker and action: String or Date ??
Hi,
I have struts2-core-2.1.8.jar and xwork-core-2.1.6.jar in my classpath.
I read that there are many problems of conversion using the datetimepicker tag.
I checked the vault page here :
http://cwiki.apache.org/S2WIKI/troubleshooting-guide-migrating-from-struts-20x-to-21x.html#TroubleshootingguidemigratingfromStruts2.0.xto2.1.x-Userdefinedconverter%2528subclassingStrutsTypeConverter%2529willnolongerbeneededwhenusingdatetimepicker%253A
But what exactly is the type of the getter/setter in the action ??
For instance if I use this line in a JSP :
<sx:datetimepicker name="expirationDate" key=".dateexpiMois" displayFormat="MM/yyyy" required="true"/>
What getters should i get in my action ?
java.util.Date expirationDate;
//String expirationDate;
public java.util.Date getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(java.util.Date expirationDate) {
this.expirationDate = expirationDate;
}
==> I get this error :
java.lang.NoSuchMethodException: com.eni.dvtejb.clientStruts2.action.PaiementAction.setExpirationDate([Ljava.lang.String;)
And if i use getter/setter of type String, it complains about some RFC format that is not valid.
So how exactly does it work ? Can someone provide a good example with the code for the action and the code for the JSP with the datetimepicker tag ?
Thanks.
---------------------------------------------------------------------
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
Re: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Zoran Avtarovski <zo...@sparecreative.com>.
HI Fernando,
For what it¹s worth in applications where we have a diverse range of locales
we found that it was best to create our own date converter.
The date converter then reads our properties file which contains an entry
with a comma delimited list of date formats which the date converters tries
in sequence and only if it fails does it throw an error.
We¹ve now developed about 6 applications that our clients use in non-English
countries and we¹re finding it works great.
If you want the source code just email me off list.
Z.
>
>
> Any advice, please ?
> Thanks.
>
>
> -----Message d'origine-----
> De : Celinio Fernandes [mailto:cel975@yahoo.com]
> Envoyé : dimanche 15 novembre 2009 23:08
> À : Struts Users Mailing List
> Objet : [Struts 2.1.8] datetimepicker and action: String or Date ??
>
> Hi,
> I have struts2-core-2.1.8.jar and xwork-core-2.1.6.jar in my classpath.
>
> I read that there are many problems of conversion using the datetimepicker
> tag.
>
> I checked the vault page here :
> http://cwiki.apache.org/S2WIKI/troubleshooting-guide-migrating-from-struts-20x
> -to-21x.html#TroubleshootingguidemigratingfromStruts2.0.xto2.1.x-Userdefinedco
> nverter%2528subclassingStrutsTypeConverter%2529willnolongerbeneededwhenusingda
> tetimepicker%253A
>
>
> But what exactly is the type of the getter/setter in the action ??
>
> For instance if I use this line in a JSP :
> <sx:datetimepicker name="expirationDate" key=".dateexpiMois"
> displayFormat="MM/yyyy" required="true"/>
>
>
> What getters should i get in my action ?
>
> java.util.Date expirationDate;
> //String expirationDate;
>
> public java.util.Date getExpirationDate() {
> return expirationDate;
> }
>
> public void setExpirationDate(java.util.Date expirationDate) {
> this.expirationDate = expirationDate;
> }
>
> ==> I get this error :
> java.lang.NoSuchMethodException:
> com.eni.dvtejb.clientStruts2.action.PaiementAction.setExpirationDate([Ljava.la
> ng.String;)
>
> And if i use getter/setter of type String, it complains about some RFC format
> that is not valid.
>
> So how exactly does it work ? Can someone provide a good example with the code
> for the action and the code for the JSP with the datetimepicker tag ?
>
> Thanks.
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
RE: [Struts 2.1.8] datetimepicker and action: String or Date ??
Posted by Fernandes Celinio <cf...@sopragroup.com>.
Any advice, please ?
Thanks.
-----Message d'origine-----
De : Celinio Fernandes [mailto:cel975@yahoo.com]
Envoyé : dimanche 15 novembre 2009 23:08
À : Struts Users Mailing List
Objet : [Struts 2.1.8] datetimepicker and action: String or Date ??
Hi,
I have struts2-core-2.1.8.jar and xwork-core-2.1.6.jar in my classpath.
I read that there are many problems of conversion using the datetimepicker tag.
I checked the vault page here :
http://cwiki.apache.org/S2WIKI/troubleshooting-guide-migrating-from-struts-20x-to-21x.html#TroubleshootingguidemigratingfromStruts2.0.xto2.1.x-Userdefinedconverter%2528subclassingStrutsTypeConverter%2529willnolongerbeneededwhenusingdatetimepicker%253A
But what exactly is the type of the getter/setter in the action ??
For instance if I use this line in a JSP :
<sx:datetimepicker name="expirationDate" key=".dateexpiMois" displayFormat="MM/yyyy" required="true"/>
What getters should i get in my action ?
java.util.Date expirationDate;
//String expirationDate;
public java.util.Date getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(java.util.Date expirationDate) {
this.expirationDate = expirationDate;
}
==> I get this error :
java.lang.NoSuchMethodException: com.eni.dvtejb.clientStruts2.action.PaiementAction.setExpirationDate([Ljava.lang.String;)
And if i use getter/setter of type String, it complains about some RFC format that is not valid.
So how exactly does it work ? Can someone provide a good example with the code for the action and the code for the JSP with the datetimepicker tag ?
Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org