如何在GWT2中创建嵌套编辑器?
С您能给我一个嵌套编辑器的工作示例吗?我读过这个文件,但它对我没有帮助。在我的代码中,我有类Person和Organization如何在GWT2中创建嵌套编辑器?,gwt,gwt2,gwt-editors,Gwt,Gwt2,Gwt Editors,С您能给我一个嵌套编辑器的工作示例吗?我读过这个文件,但它对我没有帮助。在我的代码中,我有类Person和Organization 组织具有类型为人员的字段联系人 因此,我为Person创建了以下编辑器: public class PersonEditor extends Composite implements Editor<PersonProxy> { interface PersonEditorUiBinder extends UiBinder<Widget, P
组织
具有类型为人员
的字段联系人
因此,我为Person创建了以下编辑器:
public class PersonEditor extends Composite implements Editor<PersonProxy>
{
interface PersonEditorUiBinder extends UiBinder<Widget, PersonEditor>
{
}
private static PersonEditorUiBinder uiBinder = GWT.create(PersonEditorUiBinder.class);
@UiField
ValueBoxEditorDecorator<String> name;
@UiField
ValueBoxEditorDecorator<String> phoneNumber;
@UiField
ValueBoxEditorDecorator<String> email;
@UiField
CaptionPanel captionPanel;
public void setCaptionText(String captionText)
{
captionPanel.setCaptionText(captionText);
}
public PersonEditor()
{
initWidget(uiBinder.createAndBindUi(this));
}
}
最后,这里是一个类,它使用了上面描述的所有内容
public class NewOrderView extends Composite
{
interface Binder extends UiBinder<Widget, NewOrderView>
{
}
private static Binder uiBinder = GWT.create(Binder.class);
// Empty interface declaration, similar to UiBinder
interface OrganizationDriver extends SimpleBeanEditorDriver<OrganizationProxy, OrganizationEditor>
{
}
OrganizationDriver driver = GWT.create(OrganizationDriver.class);
@UiField
Button save;
@UiField
OrganizationEditor orgEditor;
OrganizationProxy organizationProxy;
public NewOrderView()
{
initWidget(uiBinder.createAndBindUi(this));
organizationProxy = createFactory().contextOrder().create(OrganizationProxy.class);
// Initialize the driver with the top-level editor
driver.initialize(orgEditor);
// Copy the data in the object into the UI
driver.edit(organizationProxy);
}
@UiHandler("save")
void buttonClick(ClickEvent e)
{
e.stopPropagation();
OrganizationProxy edited = driver.flush();
PersonProxy person = edited.getContactPerson();
// person is always null !!!
if (driver.hasErrors())
{
}
}
}
公共类NewOrderView扩展了复合
{
接口活页夹扩展了UiBinder
{
}
私有静态绑定器uiBinder=GWT.create(Binder.class);
//空接口声明,类似于UiBinder
接口OrganizationDriver扩展SimpleBeaneEdit或Driver
{
}
OrganizationDriver=GWT.create(OrganizationDriver.class);
@尤菲尔德
按钮保存;
@尤菲尔德
组织编辑;
组织代理组织代理;
public NewOrderView()
{
initWidget(uiBinder.createAndBindUi(this));
organizationProxy=createFactory().contextOrder().create(organizationProxy.class);
//使用顶级编辑器初始化驱动程序
初始化驱动程序(orgEditor);
//将对象中的数据复制到UI中
驱动程序。编辑(organizationProxy);
}
@UiHandler(“保存”)
作废按钮单击(单击事件e)
{
e、 停止传播();
OrganizationProxy edited=driver.flush();
PersonProxy person=edited.getContactPerson();
//人总是空的!!!
if(driver.hasErrors())
{
}
}
}
问题是为什么嵌套编辑器(PersonEditor)不会自动刷新?这应该发生吗?正确的解决方案是什么?
<e:ValueBoxEditorDecorator ui:field="contactPerson">
<e:valuebox>
<c:PersonEditor captionText="Contact person">
<ui:attribute name="captionText"/>
</c:PersonEditor>
</e:valuebox>
</e:ValueBoxEditorDecorator>
在Java类中,更改
@UiField
ValueBoxEditorDecorator<PersonEditor> contactPerson;
啊。。。我必须手动为联系人创建代理
public class NewOrderView extends Composite
{
public NewOrderView()
{
initWidget(uiBinder.createAndBindUi(this));
AdminRequestFactory.OrderRequestContext orderRequestContext = createFactory().contextOrder();
organizationProxy = orderRequestContext.create(OrganizationProxy.class);
organizationProxy.setContactPerson(orderRequestContext.create(PersonProxy.class));
// Initialize the driver with the top-level editor
driver.initialize(orgEditor);
// Copy the data in the object into the UI
driver.edit(organizationProxy);
}
}
好啊我试过了。当我从
OrganizationEditor
获取OrganizationProxy
时,其contactPerson
为空。因此,嵌套的PersonEdit
中的数据没有复制到finalOrganizationProxy
。你知道为什么吗?如果你单独使用OrganizationEditor
时它能工作,也许当它嵌套时它不会自动刷新?它永远不会工作:)那么它应该自动刷新吗?如果不是在哪里(在代码中)以及我应该如何刷新它?当然,嵌套时它不会神奇地工作;-)在文档(code.google.com/webtoolkit/doc/2.2/DevGuideUiEditors.html)中,查看“快速启动”和“常规工作流”部分:在方法save()中,它显示了如何进行刷新,即获取表单到bean的日期(当用户按下表单中的“保存”或“确定”按钮时可以调用)使用自制编辑器与使用文本框或其他没有什么特别之处的东西相比,它只是起作用@ruslan您是否正在编辑现有的组织代理
?如果是,它是否有非空的联系人?如果没有,您必须创建一个要编辑的PersonProxy
,编辑器框架不会为您这样做。(如果您正在编辑新创建的OrganizationProxy
,则必须在编辑之前分配其联系人)。
public class NewOrderView extends Composite
{
interface Binder extends UiBinder<Widget, NewOrderView>
{
}
private static Binder uiBinder = GWT.create(Binder.class);
// Empty interface declaration, similar to UiBinder
interface OrganizationDriver extends SimpleBeanEditorDriver<OrganizationProxy, OrganizationEditor>
{
}
OrganizationDriver driver = GWT.create(OrganizationDriver.class);
@UiField
Button save;
@UiField
OrganizationEditor orgEditor;
OrganizationProxy organizationProxy;
public NewOrderView()
{
initWidget(uiBinder.createAndBindUi(this));
organizationProxy = createFactory().contextOrder().create(OrganizationProxy.class);
// Initialize the driver with the top-level editor
driver.initialize(orgEditor);
// Copy the data in the object into the UI
driver.edit(organizationProxy);
}
@UiHandler("save")
void buttonClick(ClickEvent e)
{
e.stopPropagation();
OrganizationProxy edited = driver.flush();
PersonProxy person = edited.getContactPerson();
// person is always null !!!
if (driver.hasErrors())
{
}
}
}
<e:ValueBoxEditorDecorator ui:field="contactPerson">
<e:valuebox>
<c:PersonEditor captionText="Contact person">
<ui:attribute name="captionText"/>
</c:PersonEditor>
</e:valuebox>
</e:ValueBoxEditorDecorator>
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
....>
<ui:style src="../common.css"/>
<g:CaptionPanel ui:field="captionPanel">
<myui:VerticalFlowPanel>
<g:HTMLPanel>
<table class="{style.forform}">
// your other input fields
</table>
</g:HTMLPanel>
// Add the PersonEditor to the FlowPanel
<c:PersonEditor captionText="Contact person">
<ui:attribute name="captionText"/>
</c:PersonEditor>
</myui:VerticalFlowPanel>
</g:CaptionPanel>
</ui:UiBinder>
@UiField
ValueBoxEditorDecorator<PersonEditor> contactPerson;
@UiField
PersonEditor contactPerson;
public class NewOrderView extends Composite
{
public NewOrderView()
{
initWidget(uiBinder.createAndBindUi(this));
AdminRequestFactory.OrderRequestContext orderRequestContext = createFactory().contextOrder();
organizationProxy = orderRequestContext.create(OrganizationProxy.class);
organizationProxy.setContactPerson(orderRequestContext.create(PersonProxy.class));
// Initialize the driver with the top-level editor
driver.initialize(orgEditor);
// Copy the data in the object into the UI
driver.edit(organizationProxy);
}
}