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

StackOverflow https://stackoverflow.com/questions/63935

  •  09-06-2019
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top