Using own Date type in Formbeans...
Hello, i am using a user-defined Date type for FormBeans. So i can change the Display-Format (in MyDate.toString()) But now i get an error message (see below). Must i change the constructor to accept the new Format? thanks, Andreas HTTP ERROR: 500 BeanUtils.populate INFO: Processing a 'POST' for path '/a_dv_07_03_bildungsgang_aendern' 13:11:58.213 WARN!! Exception for /webapp/dv/a_dv_07_03_bildungsgang_aendern.do java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(Property Utils.java:1650) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(Property Utils.java:1545) at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils. java:1574) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:919 ) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:978) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProc essor.java:779) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja va:246) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:129 2) 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.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:366 ) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati onHandler.java:292) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5 77) at org.mortbay.http.HttpContext.handle(HttpContext.java:1682) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication Context.java:544) at org.mortbay.http.HttpContext.handle(HttpContext.java:1632) at org.mortbay.http.HttpServer.service(HttpServer.java:875) at org.mortbay.http.HttpConnection.service(HttpConnection.java:806) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:956) at org.mortbay.http.SocketChannelListener.handle(SocketChannelListener.j ava:284) at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743) at java.lang.Thread.run(Thread.java:536) -- Dipl. Ing. (BA) Andreas Langmann Software Developer ISB AG Karlstr. 52-54 76133 Karlsruhe Telefon: +49 (0)721/82800-0 Telefax: +49 (0)721/82800-82 Email: [EMAIL PROTECTED] Internet: http://www.isb-ag.de -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Using own Date type in Formbeans...
Additional Information: i extend java.sql.Date (also tried java.util.Date, but no difference...) Andreas Langmann wrote: Hello, i am using a user-defined Date type for FormBeans. So i can change the Display-Format (in MyDate.toString()) But now i get an error message (see below). Must i change the constructor to accept the new Format? thanks, Andreas HTTP ERROR: 500 BeanUtils.populate INFO: Processing a 'POST' for path '/a_dv_07_03_bildungsgang_aendern' 13:11:58.213 WARN!! Exception for /webapp/dv/a_dv_07_03_bildungsgang_aendern.do java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(Property Utils.java:1650) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(Property Utils.java:1545) at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils. java:1574) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:919 ) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:978) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProc essor.java:779) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja va:246) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:129 2) 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.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:366 ) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati onHandler.java:292) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5 77) at org.mortbay.http.HttpContext.handle(HttpContext.java:1682) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication Context.java:544) at org.mortbay.http.HttpContext.handle(HttpContext.java:1632) at org.mortbay.http.HttpServer.service(HttpServer.java:875) at org.mortbay.http.HttpConnection.service(HttpConnection.java:806) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:956) at org.mortbay.http.SocketChannelListener.handle(SocketChannelListener.j ava:284) at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743) at java.lang.Thread.run(Thread.java:536) -- Dipl. Ing. (BA) Andreas Langmann Software Developer ISB AG Karlstr. 52-54 76133 Karlsruhe Telefon: +49 (0)721/82800-0 Telefax: +49 (0)721/82800-82 Email: [EMAIL PROTECTED] Internet: http://www.isb-ag.de -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- Dipl. Ing. (BA) Andreas Langmann Software Developer ISB AG Karlstr. 52-54 76133 Karlsruhe Telefon: +49 (0)721/82800-0 Telefax: +49 (0)721/82800-82 Email: [EMAIL PROTECTED] Internet: http://www.isb-ag.de -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re[2]: Using own Date type in Formbeans...
Hello Andreas, given your infos I can only guess what goes wrong. Setting the props in your action form fails because of your setters. Can you mail your jsp and your form bean. Friday, November 8, 2002, 2:08:49 PM, you wrote: AL Additional Information: i extend java.sql.Date (also tried AL java.util.Date, but no difference...) AL Andreas Langmann wrote: Hello, i am using a user-defined Date type for FormBeans. So i can change the Display-Format (in MyDate.toString()) But now i get an error message (see below). Must i change the constructor to accept the new Format? thanks, Andreas HTTP ERROR: 500 BeanUtils.populate INFO: Processing a 'POST' for path '/a_dv_07_03_bildungsgang_aendern' 13:11:58.213 WARN!! Exception for /webapp/dv/a_dv_07_03_bildungsgang_aendern.do java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(Property Utils.java:1650) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(Property Utils.java:1545) at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils. java:1574) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:919 ) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:978) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProc essor.java:779) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja va:246) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:129 2) 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.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:366 ) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati onHandler.java:292) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5 77) at org.mortbay.http.HttpContext.handle(HttpContext.java:1682) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication Context.java:544) at org.mortbay.http.HttpContext.handle(HttpContext.java:1632) at org.mortbay.http.HttpServer.service(HttpServer.java:875) at org.mortbay.http.HttpConnection.service(HttpConnection.java:806) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:956) at org.mortbay.http.SocketChannelListener.handle(SocketChannelListener.j ava:284) at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743) at java.lang.Thread.run(Thread.java:536) -- Dipl. Ing. (BA) Andreas Langmann Software Developer ISB AG Karlstr. 52-54 76133 Karlsruhe Telefon: +49 (0)721/82800-0 Telefax: +49 (0)721/82800-82 Email: [EMAIL PROTECTED] Internet: http://www.isb-ag.de -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- Best regards, Dirk -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: Using own Date type in Formbeans...
Actually i use Struts Milestone build. Should i try to update used librarys? TIA Andreas Langmann jsp ---cut--- html:text property=bildungsgang.txt_bgaend_gueltigkeit_von/ ---cut--- FormBean ---cut--- // java.sql.Date mTxtBgaendGueltigkeitVon; public java.sql.Date getTxt_bgaend_gueltigkeit_von() { return mTxtBgaendGueltigkeitVon; } public void setTxt_bgaend_gueltigkeit_von(java.sql.Date txtBgaendGueltigkeitVon) { mTxtBgaendGueltigkeitVon = txtBgaendGueltigkeitVon; } ---cut--- CLASS DateWrapper package de.km.bw.estat.struts.utils; import java.sql.Date; /** * @author alangman * */ public class DateWrapper extends java.sql.Date { static String cFormatStr = dd.MM.; public static void setFormatStr(String formatStr) { cFormatStr = formatStr; } public DateWrapper(long date) { super(date); } public String toString() { java.text.DateFormat df = new java.text.SimpleDateFormat(cFormatStr); return df.format(this); } } Postfach 4711 wrote: Hello Andreas, given your infos I can only guess what goes wrong. Setting the props in your action form fails because of your setters. Can you mail your jsp and your form bean. Friday, November 8, 2002, 2:08:49 PM, you wrote: AL Additional Information: i extend java.sql.Date (also tried AL java.util.Date, but no difference...) AL Andreas Langmann wrote: Hello, i am using a user-defined Date type for FormBeans. So i can change the Display-Format (in MyDate.toString()) But now i get an error message (see below). Must i change the constructor to accept the new Format? thanks, Andreas HTTP ERROR: 500 BeanUtils.populate INFO: Processing a 'POST' for path '/a_dv_07_03_bildungsgang_aendern' 13:11:58.213 WARN!! Exception for /webapp/dv/a_dv_07_03_bildungsgang_aendern.do java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(Property Utils.java:1650) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(Property Utils.java:1545) at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils. java:1574) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:919 ) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:978) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProc essor.java:779) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja va:246) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:129 2) 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.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:366 ) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati onHandler.java:292) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5 77) at org.mortbay.http.HttpContext.handle(HttpContext.java:1682) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication Context.java:544) at org.mortbay.http.HttpContext.handle(HttpContext.java:1632) at org.mortbay.http.HttpServer.service(HttpServer.java:875) at org.mortbay.http.HttpConnection.service(HttpConnection.java:806) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:956) at org.mortbay.http.SocketChannelListener.handle(SocketChannelListener.j ava:284) at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743) at java.lang.Thread.run(Thread.java:536) -- Dipl. Ing. (BA) Andreas Langmann Software Developer ISB AG Karlstr. 52-54 76133 Karlsruhe Telefon: +49 (0)721/82800-0 Telefax: +49 (0)721/82800-82 Email: [EMAIL PROTECTED] Internet: http://www.isb-ag.de -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- Best regards, Dirk -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org -- Dipl. Ing. (BA)
Re[2]: Using own Date type in Formbeans...
Hello Andreas, you should consider making your txt_bgaend_gueltigkeit_von property a String. As Craig pointed out This is critically important for re-displaying invalid input. Then you should have no problems and can later use BeanUtils to convert it to Date. Friday, November 8, 2002, 3:24:24 PM, you wrote: AL Actually i use Struts Milestone build. Should i try to update used AL librarys? AL TIA AL Andreas Langmann AL jsp AL ---cut--- AL html:text property=bildungsgang.txt_bgaend_gueltigkeit_von/ AL ---cut--- AL FormBean AL ---cut--- AL // AL java.sql.Date mTxtBgaendGueltigkeitVon; AL public java.sql.Date getTxt_bgaend_gueltigkeit_von() { AL return mTxtBgaendGueltigkeitVon; AL } AL public void setTxt_bgaend_gueltigkeit_von(java.sql.Date AL txtBgaendGueltigkeitVon) { AL mTxtBgaendGueltigkeitVon = txtBgaendGueltigkeitVon; AL } AL ---cut--- AL CLASS DateWrapper AL package de.km.bw.estat.struts.utils; AL import java.sql.Date; AL /** AL * @author alangman AL * AL */ AL public class DateWrapper extends java.sql.Date { AL static String cFormatStr = dd.MM.; AL public static void setFormatStr(String formatStr) { AL cFormatStr = formatStr; AL } AL public DateWrapper(long date) { AL super(date); AL } AL public String toString() { AL java.text.DateFormat df = new AL java.text.SimpleDateFormat(cFormatStr); AL return df.format(this); AL } AL } AL AL Postfach 4711 wrote: Hello Andreas, given your infos I can only guess what goes wrong. Setting the props in your action form fails because of your setters. Can you mail your jsp and your form bean. Friday, November 8, 2002, 2:08:49 PM, you wrote: AL Additional Information: i extend java.sql.Date (also tried AL java.util.Date, but no difference...) AL Andreas Langmann wrote: Hello, i am using a user-defined Date type for FormBeans. So i can change the Display-Format (in MyDate.toString()) But now i get an error message (see below). Must i change the constructor to accept the new Format? thanks, Andreas HTTP ERROR: 500 BeanUtils.populate INFO: Processing a 'POST' for path '/a_dv_07_03_bildungsgang_aendern' 13:11:58.213 WARN!! Exception for /webapp/dv/a_dv_07_03_bildungsgang_aendern.do java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(Property Utils.java:1650) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(Property Utils.java:1545) at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils. java:1574) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:919 ) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:978) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProc essor.java:779) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja va:246) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:129 2) 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.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:366 ) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati onHandler.java:292) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5 77) at org.mortbay.http.HttpContext.handle(HttpContext.java:1682) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication Context.java:544) at org.mortbay.http.HttpContext.handle(HttpContext.java:1632) at org.mortbay.http.HttpServer.service(HttpServer.java:875) at org.mortbay.http.HttpConnection.service(HttpConnection.java:806) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:956) at org.mortbay.http.SocketChannelListener.handle(SocketChannelListener.j ava:284) at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743) at java.lang.Thread.run(Thread.java:536) -- Dipl. Ing. (BA) Andreas Langmann Software Developer ISB AG Karlstr. 52-54 76133 Karlsruhe Telefon: +49 (0)721/82800-0 Telefax: +49
Re: Using own Date type in Formbeans...
Yeah! It works my FormBean variable type is myDate (from java.sql.Date or java.util.Date ) and i used the code from an older posting to make it. Okay, what to do: Change the Date type in the code below to myDate. And now your date type will use your format for display... - Date: Thu, 17 Oct 2002 12:22:35 -0400 From: Rick Reumann [EMAIL PROTECTED] Subject: [ConvertUtils] Converter for java.util.Date Content-Type: text/plain; charset=us-ascii Hey Elder, (posting this to Struts list as well in case anyone else finds it useful while digging through the archives) I modified the code you sent just a bit and also provided a method taking a format String for how they want the date formatted (actually someone might want to modify the code with a default format, but I want to be forced to provide one). I still haven't gotten around to actually modifying the StringConverter class to handle the other direction (String to java.util.Date) to avoid having to register the extra custom StringConverter class below. I'll get around to it some time:) To use these converters so that BeanUtils.copyProperties( ) works in both directions I just added a static block to the top of my dispatch Action ... static { DateBeanUtilsConverter dateConverter = new DateBeanUtilsConverter(); dateConverter.setFormatPattern( MMdd ); StringBeanUtilsConverterDate myStringConverter = new StringBeanUtilsConverterDate(); myStringConverter.setFormatPattern( MMdd ); ConvertUtils.register( dateConverter, java.util.Date.class ); ConvertUtils.register( myStringConverter, String.class ); } The two classes are listed below. All seems to be working fine. /** coverts java.util.Date to String using BeanUtils ***/ import org.apache.commons.beanutils.Converter; import java.text.*; import java.util.*; import corporate.*; public class DateBeanUtilsConverter implements Converter { private String formatPattern = null; public void setFormatPattern(String formatPattern) { this.formatPattern = formatPattern; } public Object convert(Class type, Object value) { Date date = null; if (value != null (value instanceof String) (type == Date.class)) { try { String s = value.toString(); SimpleDateFormat formatter = new SimpleDateFormat(formatPattern); date = formatter.parse(s); } catch (Exception e) { ErrorLogging.println(DateBeanUtilsConverter: + e); } } return date; } } /** coverts String to java.util.Date using BeanUtils ***/ import org.apache.commons.beanutils.Converter; import org.apache.commons.beanutils.converters.*; import java.text.*; import java.util.*; import corporate.*; public class StringBeanUtilsConverterDate implements Converter { private static final StringConverter stringConverter = new StringConverter(); private String formatPattern = null; public void setFormatPattern(String formatPattern) { this.formatPattern = formatPattern; } public Object convert(Class type, Object value) { Object returnValue = null; if (value != null) { if (type == String.class (value instanceof Date)) { SimpleDateFormat formatter = new SimpleDateFormat(formatPattern); String dateString = formatter.format(value); returnValue = dateString; } else { returnValue = stringConverter.convert(type, value); } } return returnValue; } } - -- Dipl. Ing. (BA) Andreas Langmann Software Developer ISB AG Karlstr. 52-54 76133 Karlsruhe Telefon: +49 (0)721/82800-0 Telefax: +49 (0)721/82800-82 Email: [EMAIL PROTECTED] Internet: http://www.isb-ag.de -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org