我正在尝试运行一个带有子编辑器的编辑器示例。刷新父级时,子编辑器的值为空。类是Person和Address。主编辑器是:
// editor fields
public TextField firstname;
public TextField lastname;
public NumberField<Integer> id;
public AddressEditor address = new AddressEditor();
public PersonEditor(Person p){
asWidget();
}
@Override
public Widget asWidget() {
setWidth(400);
setBodyStyle("padding: 5px;");
setHeaderVisible(false);
VerticalLayoutContainer c = new VerticalLayoutContainer();
id = new NumberField<Integer>(new IntegerPropertyEditor());
// id.setName("id");
id.setFormat(NumberFormat.getFormat("0.00"));
id.setAllowNegative(false);
c.add(new FieldLabel(id, "id"), new VerticalLayoutData(1, -1));
firstname = new TextField();
// firstname.setName("firstname");
c.add(new FieldLabel(firstname, "firstname"), new VerticalLayoutData(1, -1));
lastname = new TextField();
lastname.setName("lastname");
c.add(new FieldLabel(lastname, "lastname"), new VerticalLayoutData(1, -1));
c.add(address);
add(c);
return this;子编辑器:
public class AddressEditor extends Composite implements Editor<Address> {
private AddressProperties props = GWT.create(AddressProperties.class);
private ListStore<Address> store = new ListStore<Address>(props.key());
ComboBox<Address> address;
public AddressEditor() {
for(int i = 0; i < 5; i ++)
store.add(new Address("city" + i));
address = new ComboBox<Address>(store, props.nameLabel());
address.setAllowBlank(false);
address.setForceSelection(true);
address.setTriggerAction(TriggerAction.ALL);
initWidget(address);
}驱动程序就是在这里创建的:
private HorizontalPanel hp;
private Person googleContact;
PersonDriver driver = GWT.create(PersonDriver.class);
public void onModuleLoad() {
hp = new HorizontalPanel();
hp.setSpacing(10);
googleContact = new Person();
PersonEditor pe = new PersonEditor(googleContact);
driver.initialize(pe);
driver.edit(googleContact);
TextButton save = new TextButton("Save");
save.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
googleContact = driver.flush();
System.out.println(googleContact.getFirstname() + ", " + googleContact.getAddress().getCity());
if (driver.hasErrors()) {
new MessageBox("Please correct the errors before saving.").show();
return;
}
}
});googleContact.getFirstname()的值已填充,但googleContact.getAddress()始终为空。我错过了什么?
发布于 2013-02-09 03:07:26
AddressEditor需要映射到Address模型--目前,似乎还没有,除非Address只有一个getter/setter,称为getAddress()和setAddress(Address),这并没有多大意义。
如果您只需要一个ComboBox<Address> (它已经实现了Editor<Address> ),那么可以考虑将该组合直接放入PersonEditor中。否则,您将需要将@Path("")添加到AddressEditor.address字段,以指示它应该直接编辑值本身,而不是子属性(即person.getAddress().getAddress())。
构建地址编辑器的另一种方法是在AddressEditor中列出Address类型的每个属性。这是驱动程序默认情况下所期望的,所以当它看到名为“address”的字段时,它会感到困惑。
关于代码本身的两个快速想法:不需要将一个人传递到PersonEditor中-这是驱动程序本身的工作。其次,您的编辑器字段不需要为public,它们不能为private。
https://stackoverflow.com/questions/14777225
复制相似问题