Laurie Harper wrote:
Sandra Reichert wrote:
Hi,

I have an input form in jsp. After submitting empty fields (user entered
nothing in input field) are set by default with specific values
depending on their data typ.
So an empty Integer field is set to 0, an String field to "" an so on.

But i want to have a null value for empty fields.
Or in other words: How can i decide if for example the 0 is entered by
user or the default initialization.

This is one of the many reasons you should prefer String-valued form bean properties, rather than using int/Integer, etc. That way, you can redisplay incorrect/invalid inputs for the user to edit and correct. What if the user types 'two' into a field that's backed by an Integer-typed property? Resetting it to 0 is clearly not what you want, but resetting it to null isn't great either.

If you don't care about redisplaying input values and/or you really can't change your form properties to be String-typed, the best you can do it to re-configure the BeanUtils converters to use null as a default instead of 0.

I use Long/Integer for hidden, state fields that the user won't see/can't change. I've been thinking of using them for <option...> values as well, since the user can't see those either. Idea being that the only way the user can change these values is by editing the HTML source. If they do that, all bets are off :). As long as it doesn't muck up the application. Though I should probably point out the people who are using my web apps are the same people who requested it, and no more. Things would obviously be a little different on a public web site if a user managed to edit someone else's profile by changing something like <input type="hidden" name="userId" value="4"> to another number on the system :).

- Scott

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

Reply via email to