Friday, January 21, 2011

Can I submit a Struts form that references POJO (i.e. not just String or boolean) fields?

I have a Struts (1.3x) ActionForm that has several String and boolean properties/fields, but also has some POJO fields.

so my form looks something like:

MyForm extends ActionForm {
    private String name;
    private int id;
    private Thing thing;

    ...getters/setters...
}

In the JSP I can reference the POJO's fields thusly:

<html:text property="thing.thingName" />

...and the values display correctly, but if I try to submit the form I get the ServletException: BeanUtils.populate error.

There seems to be a lot of information about this general topic on the web, but none really addresses my specific question, which is: shouldn't I be able to submit a form in Struts that contains fields that are POJOs?

  • You can, as long as the fields follow the JavaBean conventions and the setter takes something Struts can understand.

    So Thing needs getThingName() and setThingName(String).

0 comments:

Post a Comment