Matthias Kerkhoff wrote:
> Hi all,
>
> I've noticed a problem with forms containing optional fields.
>
> Suppose you have a form containing some optional fields, that the
> user can fill with some value or leave blank. If form validation
> fails (for example because the user has not filled in values for
> some _other_ mandatory fields) the usual pattern is to redisplay
> the form page to the user together with some error messages.
>
> However, due to the way the form-field tags like <struts:text>
> are implemented, the optional fields will then contain default
> values, if the associated properties are not of type String.
>
> Example:
>
> Imagine a slightly modified subscription.jsp from the struts-example,
> that asks the user for an additional (and optional) Integer property.
>
> <tr>
> <th align="right">
> <struts:message key="prompt.intProperty"/>
> </th>
> <td align="left">
> <struts:text property="intProperty"/>
> </td>
> </tr>
>
> If the user enters invalid values for - let's say - the mail hostname
> and leaves the intProperty field blank, the subscription.jsp will be
> redisplayed. This time, the intProperty field will contain a 0 (instead
> of being empty). Depending on the semantic behind intProperty this could
> make a serious difference, when this form is resubmitted.
>
Couldn't you use a variable of type java.lang.Integer instead of an int? That
way, the default value for the property would be null, and not 0.
JB.
>
> Is this behaviour intended ?
>
> --
> Matthias mailto:[EMAIL PROTECTED]
--
Jean-Baptiste Nizet
[EMAIL PROTECTED]
R&D Engineer, S1 Belgium
Kleine Kloosterstraat, 23
B-1932 Sint-Stevens Woluwe
+32 2 200 45 42