I don't understand the way struts treats the ActionForm bean in Struts 1.3. This is how it goes...
I have a <html:form action="/myaction.do"><html:text property="myinteger"/></html:form>. I understand that this creates a new ActionForm bean with a type and a scope specified in struts-config.xml if the bean doesn't already exist.
The ActionForm bean I'm using has an Integer attribute which I want to have value -1 if no value was introduced in the form.
The first time I present the jsp page that has the <html:form> nothing appears in that <html:text property="myinteger"/> as I expect because the ActionForm bean has just been created and that Integer property has a default value of null.
My problem is that in my MyAction class, the first time I get my AtionForm subclass something(this is what I'm trying to find out) has assigned a default value of 0 to my Integer property which I was expecting to still be null.
I tried to prevent this by chaning the myinteger setter in my ActionForm subclass to:
but when debugging the setter method already comes with a 0.
I'd guess because if the string from the form is blank (it will never be null from the form) that the type conversion will make it a zero.
Joined: Sep 18, 2009
Thanks for you response David!
You are right, a blank field in the form is a request paramter with an empty string, not null. But my question is, where does this convertion from request parameter to Integer happens and how can I change that behavior so that I don't end up with 0.