Sorry, In my last reply, I wasn't "focused" on the important fact that this date value is coming from a webform. What you would really want in this case is a way to specify a nested setProperty.

So let's say you create a bean class that can represent a date and has separate numeric properties for month, day-of-month, year, as they are represented in your form. (This sounds just like the java.util.Date class, doesn't it? But then all those methods have been deprecated. Shh! Don't tell anyone!)

Then your input element could be something like this

<input type=input name="userDate.year">

and JSP would automatically call beanFoo.setYear(value). Unfortunately, I don't believe that that is currently in the JSP spec. I think it was in an earlier draft, but got taken out. Maybe it will show up later. Sure would be useful.

Yours, JonTom

    John Thomas Kittredge
    ITA Software, Inc
    Cambridge, Massachusetts

JonTom Kittredge wrote:

Frank, I think that what you're running into are the limitations of assigning properties from a string value. From what I understand, JSP is effectively doing a setProperty() on the request parameters that match properties in your bean, but remember that these parameters are passed as Strings.

I believe that the relevant part of the JSP spec (I'm quoting from the 1.1 version), Section 2.13.2, paragraph 3, page 65:

Properties in a Bean can be set from one or more parameters in the request object, from a String constant, or from a compted request-time expression. Simple and indexed properties can be set using setProperties. The only types of properties that can be assigned to/from String constants and request parameter values are those listed in table 2-4; the conversion applied is shown in that table.


The table lists only the primitive types -- boolean, byte, char, double, int, float and long.

I think that what you would want to do in this case is to have add an extra date property to your bean that gets/sets the date as either a long (internal format) or as a string that you can parse. For example:

public long getUserDateInternal() {
returns getUserDate().getTime();
}
public void setUserDateInternal(long value) {
setUserDate(new Date(value));
}


Hope this helps.

Yours, JonTom

    John Thomas Kittredge
    ITA Software, Inc
    Cambridge, Massachusetts
 

Reply via email to