Discussions

Web tier: servlets, JSP, Web frameworks: Submiting Date Objects in html forms using struts

  1. Submiting Date Objects in html forms using struts (3 messages)

    Hi all,

    What is the best strategy to submit Date objects from html forms using struts framework?. When I have a FormBean with a Date property. The struts API cann't populate this Bean, dispatching the following error:

    java.lang.IllegalArgumentException: argument type mismatch
    ...
    org.apache.struts.util.PropertyUtils.setSimpleProperty(PropertyUtils.java:988)

    I'll appreciate your help.

    Cesar.
  2. The page isnt actually submitting a Date object, but a String object that represents a date. Its just a HTTP parameter being passed.

    Struts will populate your FormBean with that String and then your FormBean can validate it and convert it to a Date object.
  3. Thanks!,
    That means that I cann't have a FormBean like this, can I?:
     public class MyFormBean extends ActionForm{
        private Date myDateField;
        ...
        public void setMyDateField(Date date){
           myDateField = date;
        }
       ...
    }

    Instead, Should I have allways String propeties?. like this:

     public class MyFormBean extends ActionForm{
        private Date myDateField;
        ...
        public void setMyDateField(String date){
           myDateField = convertToDate(date);
        }
       ...
    }

    Am I right?...


    Thanks for your help.
  4. Right. No data type conversions are performed in v1.0 and Im pretty sure that hasnt changed in v1.1. Dont hold me to that though.

    The jakarta commons beanutils package is used in v1.1 and the PropertyUtils class your using has been deprecated.