Gwt 如何实现LeafValueEditor<;地址>;
我试图理解如何为非不变对象正确实现LeafValueEditor。这两种方法中哪一种是正确的,或者应该使用其他方法Gwt 如何实现LeafValueEditor<;地址>;,gwt,Gwt,我试图理解如何为非不变对象正确实现LeafValueEditor。这两种方法中哪一种是正确的,或者应该使用其他方法 public class Address { public String line1; public String city; public String zip; } 备选案文1: public class AddressEditor implements LeafValueEditor<Address> { private String
public class Address {
public String line1;
public String city;
public String zip;
}
备选案文1:
public class AddressEditor implements LeafValueEditor<Address>
{
private String line1;
private String city;
private String zip;
private Address address;
public void setValue(Address value)
{
this.line1 = value.line1;
this.city = value.city;
this.zip = value.zip;
this.address = value;
}
public Address getValue()
{
this.address.line1 = this.line1;
this.address.city = this.city;
this.address.zip = this.zip;
return this.address;
}
}
公共类AddressEditor实现了LeafValueEditor
{
专用字符串行1;
私人城市;
私人字符串拉链;
私人地址;
公共无效设置值(地址值)
{
this.line1=value.line1;
this.city=value.city;
this.zip=value.zip;
this.address=值;
}
公共广播getValue()
{
this.address.line1=this.line1;
this.address.city=this.city;
this.address.zip=this.zip;
返回此地址;
}
}
备选案文2:
public class AddressEditor implements LeafValueEditor<Address>
{
private String line1;
private String city;
private String zip;
public void setValue(Address value)
{
this.line1 = value.line1;
this.city = value.city;
this.zip = value.zip;
}
public Address getValue()
{
Address a = new Address();
this.a.line1 = this.line1;
this.a.city = this.city;
this.a.zip = this.zip;
return a;
}
}
公共类AddressEditor实现了LeafValueEditor
{
专用字符串行1;
私人城市;
私人字符串拉链;
公共无效设置值(地址值)
{
this.line1=value.line1;
this.city=value.city;
this.zip=value.zip;
}
公共广播getValue()
{
地址a=新地址();
this.a.line1=this.line1;
this.a.city=this.city;
this.a.zip=this.zip;
返回a;
}
}
可能两者都不起作用,尽管从技术上讲两者都可以起作用
LeafValueEditor是叶值的编辑器,即通常不包含其他值的值。通常,页面上可见的文本、日期或数字字段是叶编辑器,这些叶节点包含在普通编辑器中
在这种情况下,它可能看起来像这样:
public class AddressEditor extends Composite implements Editor<Address> {
// not private, fields must be visible for the driver to manipulate them
// automatically, could be package-protected, protected, or public
protected TextBox line1;//automatically maps to getLine1()/setLine1(String)
protected TextBox city;
protected TextBox zip;
public AddressEditor() {
//TODO build the fields, attach them to some parent, and
// initWidget with them
}
}
public-class-AddressEditor扩展了Composite-implements-Editor,以获得更多关于如何通过一点连接自动组合这些内容的详细信息