Problem with html:text - setting empty strings instead of null values
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Bhavin_Shah
Posted On:   Monday, May 26, 2003 11:50 PM

Hello, I am using tags in a form. Even if the user does not enter any values in the text fields, i.e they are completely blank, on submit of the form, empty strings ("") get set in the Form Bean insted of null values. I am already setting the corresponding String variables to null in the reset() method of the Form Bean. However, on submit of the form, these variables get set to empty strings (""). 1. What is the default behaviour of tag w.r.t. empty/blank text fields? 2. Is there a way to fix this problem so that instead of empty strings, the values remain null? Bhavin Shah    More>>

Hello,

I am using tags in a form. Even if the user does not enter any values in the text fields, i.e they are completely blank, on submit of the form, empty strings ("") get set in the Form Bean insted of null values.


I am already setting the corresponding String variables to null in the reset() method of the Form Bean. However, on submit of the form, these variables get set to empty strings ("").


1. What is the default behaviour of tag w.r.t. empty/blank text fields?


2. Is there a way to fix this problem so that instead of empty strings, the values remain null?


Bhavin Shah

   <<Less

Re: Problem with html:text - setting empty strings instead of null values

Posted By:   Anonymous  
Posted On:   Tuesday, May 27, 2003 01:17 AM

It is not because of struts that you get empty strings this is standard http behaviour. If you don't type a value in you're text field (client side), the server get a key=value pail like 'textfieldName=' and it is automatically interpretated as an empty string.

But why do you need to make a difference between a null value or an empty string, both indicate that the user didn't give any value to that textfield.


If you really want a null value in the Form Bean make sure that the key that maps on the setter of in Form Bean isn't present in the http request and set the field in the reset method of you're Form Bean to null.

If you don't use the reset method, the first time the field will get the initial value set in you're Form Bean when you declared it and if in a request the field get a value it will keep this value until it session invalidates.

About | Sitemap | Contact