SV: date format problems

2003-03-07 Thread Søren Blidorf
Yes, it's a good point, but the only place my date is a String, is in
the ActionForm.

Would you store the date as long there?

-Oprindelig meddelelse-
Fra: apachep2 [mailto:[EMAIL PROTECTED] 
Sendt: 7. marts 2003 15:22
Til: 'Struts Users Mailing List'
Emne: RE: date format problems

Never try to store a date as a string. It creates a lot of date format
problems. As I have said, store it as a long so that you can easily do
the conversion.

-Original Message-
From: Søren Blidorf [mailto:[EMAIL PROTECTED] 
Sent: March 6, 2003 6:42 PM
To: 'Struts Users Mailing List'
Subject: SV: date format problems

Hi.
Thanks for all the answers

I was trying different things because nothing would work for me.

I need one thing:

Convert the String value theForm.GetMyDate() so that I can insert it in
my sql as -MM-dd.

I get the error java.lang.IllegalArgumentException: Cannot format given
Object as a Date

I will look at BeanUtils.copyProperties( beanToCopyTo, beanCopyingFrom
);, but it is probably to complicated for me just now!

What is the best way to fix it?

-Oprindelig meddelelse-
Fra: Chen, Gin [mailto:[EMAIL PROTECTED] 
Sendt: 6. marts 2003 16:31
Til: 'Struts Users Mailing List'
Emne: RE: date format problems

The standard for an actionForm is to have every field as String.
All conversion (which should really be thought of as business logic)
should
occur in the Action classes or further down the food chain. If this is
not
possible in your case or does not solve what your working on then can
you
please give more details?
-Tim


-Original Message-
From: Kandi Potter [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 10:21 AM
To: Struts Users Mailing List
Subject: RE: date format problems


I'm no expert at struts but I  convert and validate my dates in my
Action or
Business Class instead of the Form.  I could be completely off-base here
in
my interpretation of the struts ActionForm though  

-Original Message-
From: Søren Blidorf [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 10:07 AM
To: [EMAIL PROTECTED]
Subject: date format problems


Hi.

I have an action that gets a date from the MS SQL 2000 in -MM-dd. I
convert it with simpledateformat as dd-MM- and put it in a jsp form.
When submitting the form the date must be coverted back to -MM-DD
before another actions update the db.

I am trying to convert the date value in the ActionForm, but I am
getting the following error.

Any idears? I am lost and it is very urgent

Søren Blidorf


HTTP Status 500 - 




type Exception report

message 

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception 

javax.servlet.ServletException: BeanUtils.populate
at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:774)
at
org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.jav
a:2061)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1564)
at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:260)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:191)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authenticator
Base.java:550)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:241
5)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:180)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherVa
lve.java:170)
at
org.apache.catalina.core.StandardPipeline

Re: SV: date format problems

2003-03-07 Thread Rick Reumann
On Fri, 7 Mar 2003 15:26:49 +0100
Søren Blidorf [EMAIL PROTECTED] wrote:

 Yes, it's a good point, but the only place my date is a String, is in
 the ActionForm.
 
 Would you store the date as long there?


With all due respect to apachep2 I would store myDate as a String in an
ActionForm bean and then in your business class you store your Date as
the Date you want (I prefer java.util.Date).

So now the question becomes how do you quickly copy all of your String
form bean properties into this business bean that has a type:
java.util.Date.\

In your action you submit to you do:

BeanUtils.copyProperties( yourBusinessBean, yourActionFormBean )


BUT, as you have realized copyProperties will not work for
java.util.Date. So you need to register a converter.


I posted about this a while a back and a search of the archives reveals
the link below. I would change one thing though... following Craig's
suggestion it's cleaner to register the converter as a Plugin which you
can do easily in your struts-config file. Since all my DispatchAction
classes extend a BaseAction I registered the converter there in a static
block, which works, but it's just cleaner as a Plugin since you could
easily swap out the converter at a later time.

Let me know if this link helps. If you are still having trouble let me
know.

http://marc.theaimsgroup.com/?l=struts-userm=103487187525032w=2


-- 
Rick Reumann

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



SV: date format problems

2003-03-06 Thread Søren Blidorf
Hi.
Thanks for all the answers

I was trying different things because nothing would work for me.

I need one thing:

Convert the String value theForm.GetMyDate() so that I can insert it in
my sql as -MM-dd.

I get the error java.lang.IllegalArgumentException: Cannot format given
Object as a Date

I will look at BeanUtils.copyProperties( beanToCopyTo, beanCopyingFrom
);, but it is probably to complicated for me just now!

What is the best way to fix it?

-Oprindelig meddelelse-
Fra: Chen, Gin [mailto:[EMAIL PROTECTED] 
Sendt: 6. marts 2003 16:31
Til: 'Struts Users Mailing List'
Emne: RE: date format problems

The standard for an actionForm is to have every field as String.
All conversion (which should really be thought of as business logic)
should
occur in the Action classes or further down the food chain. If this is
not
possible in your case or does not solve what your working on then can
you
please give more details?
-Tim


-Original Message-
From: Kandi Potter [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 10:21 AM
To: Struts Users Mailing List
Subject: RE: date format problems


I'm no expert at struts but I  convert and validate my dates in my
Action or
Business Class instead of the Form.  I could be completely off-base here
in
my interpretation of the struts ActionForm though  

-Original Message-
From: Søren Blidorf [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 10:07 AM
To: [EMAIL PROTECTED]
Subject: date format problems


Hi.

I have an action that gets a date from the MS SQL 2000 in -MM-dd. I
convert it with simpledateformat as dd-MM- and put it in a jsp form.
When submitting the form the date must be coverted back to -MM-DD
before another actions update the db.

I am trying to convert the date value in the ActionForm, but I am
getting the following error.

Any idears? I am lost and it is very urgent

Søren Blidorf


HTTP Status 500 - 




type Exception report

message 

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception 

javax.servlet.ServletException: BeanUtils.populate
at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:774)
at
org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.jav
a:2061)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1564)
at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:260)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:191)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authenticator
Base.java:550)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:241
5)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:180)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherVa
lve.java:170)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:172)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:174)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i

SV: date format problems

2003-03-06 Thread Søren Blidorf
That did it, Thanks a million.

It looks almost like what I did, but I found my mistake.

-Oprindelig meddelelse-
Fra: Michael Cardon [mailto:[EMAIL PROTECTED] 
Sendt: 7. marts 2003 00:50
Til: Struts Users Mailing List
Emne: RE: date format problems

Here is what I do. The client enters a date of birth date as a string on
the
form, then I convert it to a java.sql.Date object in this method.


/**
 * Sets the dobStr
 * @param dobStr The dobStr to set
 */
public void setDobStr(String dobStr) throws
java.text.ParseException {
this.dobStr = dobStr;

// reset the Date object
this.dobDate = null;

if ((dobStr != null)  (dobStr.length()  0)) {
SimpleDateFormat sdf = new
SimpleDateFormat(MM/dd/yy);
sdf.setLenient(false);

try {
java.util.Date dt = sdf.parse(dobStr);
this.dobDate = new
java.sql.Date(dt.getTime());

} catch (ParseException pe) {
throw new java.text.ParseException(Date
Of Birth:,
pe.getErrorOffset());
}
}
}

-Original Message-
From: Søren Blidorf [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 3:42 PM
To: 'Struts Users Mailing List'
Subject: SV: date format problems


Hi.
Thanks for all the answers

I was trying different things because nothing would work for me.

I need one thing:

Convert the String value theForm.GetMyDate() so that I can insert it in
my sql as -MM-dd.

I get the error java.lang.IllegalArgumentException: Cannot format given
Object as a Date

I will look at BeanUtils.copyProperties( beanToCopyTo, beanCopyingFrom
);, but it is probably to complicated for me just now!

What is the best way to fix it?

-Oprindelig meddelelse-
Fra: Chen, Gin [mailto:[EMAIL PROTECTED]
Sendt: 6. marts 2003 16:31
Til: 'Struts Users Mailing List'
Emne: RE: date format problems

The standard for an actionForm is to have every field as String.
All conversion (which should really be thought of as business logic)
should
occur in the Action classes or further down the food chain. If this is
not
possible in your case or does not solve what your working on then can
you
please give more details?
-Tim


-Original Message-
From: Kandi Potter [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 10:21 AM
To: Struts Users Mailing List
Subject: RE: date format problems


I'm no expert at struts but I  convert and validate my dates in my
Action or
Business Class instead of the Form.  I could be completely off-base here
in
my interpretation of the struts ActionForm though

-Original Message-
From: Søren Blidorf [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 06, 2003 10:07 AM
To: [EMAIL PROTECTED]
Subject: date format problems


Hi.

I have an action that gets a date from the MS SQL 2000 in -MM-dd. I
convert it with simpledateformat as dd-MM- and put it in a jsp form.
When submitting the form the date must be coverted back to -MM-DD
before another actions update the db.

I am trying to convert the date value in the ActionForm, but I am
getting the following error.

Any idears? I am lost and it is very urgent

Søren Blidorf


HTTP Status 500 -




type Exception report

message

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception

javax.servlet.ServletException: BeanUtils.populate
at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:774)
at
org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.jav
a:2061)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1564)
at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:260)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:191)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643