论坛首页 入门技术论坛

当POJO对象中,有个属性是SET类型(即多值!)webwork该怎么赋值??

浏览 3512 次
该帖已经被评为新手帖
作者 正文
   发表时间:2006-10-27  
本人有一POJO

POJO类

public class Datumbasicinfo  implements java.io.Serializable {


    // Fields   

     private Long id;
     private Long isenable;
     private Set clientinfos = new HashSet(0);//client类

public Datumbasicinfo() {
    }
    public Long getIsenable() {
        return this.isenable;
    }
   
    public void setIsenable(Long isenable) {
        this.isenable = isenable;
    }

    public Set getClientinfos() {
        return this.clientinfos;
    }
   
    public void setClientinfos(Set clientinfos) {
        this.clientinfos = clientinfos;
    }
}

client.java
public class Clientinfo  implements java.io.Serializable {


    // Fields   

     private Long id;
     private String mobile;


    // Constructors

    /** default constructor */
    public Clientinfo() {
    }
  
    // Property accessors

    public Long getId() {
        return this.id;
    }
   
    public void setId(Long id) {
        this.id = id;
    }

    public String getMobile() {
        return this.mobile;
    }
   
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

}

view

<input name="isenable" type="text" >

<input name="mobile1" type="text" >

<input name="mobile2" type="text" >

<input name="mobile3" type="text" >
.......

以上是经过简化后的代码,实际项目中属性要比这要多。现在我想在ACTION里面一次性把这些对象全部保存。如果只是单纯的Datumbasicinfo还好说点。但这个页面已经涉及多个CLIENT对象了。不知道如何做才能使这些多个CLIENT对象传入,并组成一个数组以便当成SET传入到Datumbasicinfo中?以下是本人的ACTION中的部分代码。及实际页面图像。请提供解决途径。谢谢。
public class GcdjnAction implements Action, ModelDriven{

private Datumbasicinfo datumbasicinfo = new Datumbasicinfo();
private String act;

public String execute() throws Exception {
return null;
}

public Object getModel() {
return datumbasicinfo;
}

}
[i]
  • 大小: 1.3 MB
   发表时间:2006-11-20  
http://www.iteye.com/topic/8770
你看看这个帖子,应该有用。
0 请登录后投票
   发表时间:2006-11-21  
谢谢回复!
不过,没用!
原因:内容有点过时了,你所说的帖子,现在有更好解决的方法.就是写class-conversion.properties来完成所需功能.

看过很多帖子了,最接近也只是如何给list类赋值.请教过高手.
其回复说: set 类型的Collection的class-conversion.properties有其自己的写法. 让我自己去找.
可惜我水平有限,找了N资料也没有查我要的东西.
还请会者能以教我.
0 请登录后投票
   发表时间:2006-11-21  
moxie那个帖子适用的是旧版本,在webwork2.2之后的版本,XWorkMap/XWorkList已经被XWork(Map/List/Collection)PropertyAccessor取代掉
Map, List的写法除了和旧版本一样之外,还支持指定Key值,同样的Set也可以用这种方法试试看,定义Datumbasicinfo-conversion.properties
KeyProperty_clientinfos=id
Element_clientinfos=com.xxx.Clientinfo

传入参数:datumbasicinfo.clientinfos(1).mobile=130xxx,这样就可以绑定到对应的object了。
用makeNew关键字:datumbasicinfo.clientinfos.makeNew[0].mobile=130xxx, 可以动态创建新对象

参考一下com.opensymphony.xwork2.util.SetPropertiesTest.testAddingAndModifyingCollectionWithObjects的测试代码
0 请登录后投票
   发表时间:2006-12-01  
楼上的正解,非常感谢!
再次复习了
http://wiki.javascud.org/display/ww2cndoc/Type Conversion
才知这上面早有答案,只是原来自己读的时候太粗心了。
另:楼上所附的测试代码,我没有找到,不知在那。
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics