[英]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.我有一个 Struts (1.3x) ActionForm,它有几个 String 和 boolean 属性/字段,但也有一些 POJO 字段。
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:在 JSP 中,我可以这样引用 POJO 的字段:
<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. ...并且值显示正确,但如果我尝试提交表单,我会收到 ServletException: BeanUtils.populate 错误。
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?网络上似乎有很多关于这个一般主题的信息,但没有一个真正解决我的具体问题,即:我不应该能够在 Struts 中提交包含 POJO 字段的表单吗?
You can, as long as the fields follow the JavaBean conventions and the setter takes something Struts can understand.您可以,只要字段遵循 JavaBean 约定并且 setter 采用 Struts 可以理解的内容。
So Thing
needs getThingName()
and setThingName(String)
.所以
Thing
需要getThingName()
和setThingName(String)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.