Workaround for Booleans in Struts form bean

A coworker of mine has a Boolean property in a form bean which is supposed to remain null until some particular condition happens. The jsp contains this:

<html:hidden property=“propertyInQuestion” />

and it renders as:

<input type=“hidden” name=“propertyInQuestion” value="" />

when the value in the form bean is null. However, when the form is posted to the server, the value of false is put into the property which is incorrect. I couldn’t find anything in a google search, so I turn to my fellow dopers. How can we get it to post null back to the form bean? We are on Struts 1.2.4, BTW.

Thanks in advance,
Rob

I am making a WAG here as I haven’t played with java, but in the languages I have worked with a boolean cannot be defined as null as it is not a pointer variable. It is either initialized as true or false at runtime or possibly randomly takes whatever value was there at the address assigned to the variable. Essentially what you are needing a tri-state variable instead of a boolean (bi-state) variable.

Either way maybe this will bump it up so someone who actually knows java will see the question.

Please note that I am referring to Booleans and not booleans. For those of you unfamiliar with Java, booleans are primitive, stack-based values which are either true or false whereas Booleans are heap-based objects which can be null. Other Java primitives such as int and long have analogous object version. Since Java 1.5, autoboxing has allowed the vm to automatically convert objects to primitives and vice versa.

Rob

I guess that’s what I get for WAGging it.:smiley:

It’s finally happened: a post that is a complete mystery to me.