开发者

Multiple Model Objects for fields in one form in Struts 2

开发者 https://www.devze.com 2022-12-16 09:54 出处:网络
We have a JSP page which shows details from multiple beans. Now, there is a requirement to edit the details of these individual beans and persist it into the database. So what we are doing is having o

We have a JSP page which shows details from multiple beans. Now, there is a requirement to edit the details of these individual beans and persist it into the database. So what we are doing is having one 开发者_高级运维form with appropriate fields for each individual bean. But the ModelDriven interface allows only one object. So all the fields values will not get populated. And we cannot save the details. What can be done in this case???


Probably you can wrap your beans into single Class and provide get/set methods?

public class ModelWrapper {
    private Bean1 bean1;
    private Bean1 bean2;

    public getBean1Param1() {
        return bean1.getParam1();
    }
    ...
    public getBean2Param1() {
        return bean2.getParam1();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消