Scott Van Wart wrote:
I'm new to struts and am setting up some form beans. I'm using hibernate, and one of my tables has a lot of foreign keys. The target tables are pretty much just lookup tables, which I use to populate a good number of drop-downs on my web page. Most of the foreign keys are optional, and I'm storing the values in the action form as java.lang.Long.

The optional dropdowns all have <option value="">None</option>, but when the form is submitted, and the empty string is coerced to a java.lang.Long, it gives me a value of 0 instead of null. Am I going about this the right way? Should I just suck it up and handle the 0 value, or is there a better way to lay out my form bean's class?

That's one of the many reasons why it's strongly recommended that you use String-type properties in your form beans. Alternatively, if you really don't want to use strings, you can configure BeanUtils (which Struts is using under the covers to populate the form bean) to give you the null value you're expecting.

To do that, you need to construct a replacement converter with 'new LongConverter(null)' and register it as the converter for Long.TYPE and Long.class. [Note, I haven't tested if specifying a default value of null will work; you may have to specify an actual instance of Long, instead.]

L.


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

Reply via email to