Is there an intended usage model in struts for C++-like enumerated type
classes ala LabelValueBean?

Read no further if you understand the question.

In the application I'm working on I have several C++-like enumerated type
classes.  For example, I have one class called WidthType for which there are
WIDE, MEDIUM, and NARROW objects.  These are very similar to the
LabelValueBean class in the struts example.  One major difference though is
that the objects come from the database.  Each object has a unique id which
I consider to be the "value."  That is, two enumerator objects are equal if
they have the same id.

In my screens, I'd like the user to choose from the set of values via
ComboBox.  I looked at the struts example to see how to do this in struts.
It looked like the approach was to add a "width" property to my ActionForm
of type WidthType and use the <html:select> tag.  I tried this and
encountered two problems.

The first was with the generation of the <option> tags: the current value
wasn't marked as selected.  I investigated this and discovered that the
selectTag code records the current value as a String not as a WidthType.
So, when the optionsTag compares each value against the current value it
fails because of trying to compare a String against a WidthType.

The second problem was with copying the submitted form data back into my
ActionForm.  The value of the selected width is actually the object id, but
it's represented as a String not a WidthType.  So, the writeMethod.invoke()
call in PropertyUtils.setSimpleProperty() throws an
IllegalArgumentException.  As I see it, I have to make "width" a WidthType
because in my actual bean it's a WidthType.  If the two properties differed
in types, I wouldn't be able to use PropertyUtils.copyProperties() to
populate my bean.

My question is, am I doing this wrong or is this something that struts
hasn't addressed yet.  If I'm doing it wrong, what is the intended way?

Thanks,
Neil



Reply via email to