Reputation: 2660
I have a GWT form that changes some fields depending on what is selected in it. The form uses the Editor, Driver GWT module
The story is a person who edits her profile, and says: "I'm a User" or "I'm a Seller" (eventually "I'm something else") So depending on this choice that is in the form it self, I want to change some editors in the view (first name, last name for a person become company name, taxes serial number, while many other fields remain the same but change their place). I made two sets of UiBinder screens (one for each profile). And I have a main UiBinder that contains the checkbox "I'm a company" that handles those subeditors
What I thought I could do until now is that I have a ValueAwareEditor with subeditors
@Path("")
@UiField
protected CompanyBasicInfo basicInfoComp;
@Path("")
@UiField
protected PersonBasicInfo basicInfoPers;
both are filled by the driver, but only one of them is visible.
The thing is that I don't like the idea of having the same property in many editors, neither the performance this approach could imply
On the other side, CompanyBasicInfo and PersonBasicInfo are regular Editor implementations. So putting @Ignore on both of them is not possible since I cannot call a setValue() on them when I will want.
Also making them implement ValueAwareEditor is not clear to me since the contain regular Editor widgets, so I still won't be able to call setValue() on their fields : I'm just moving the problem a step further...
In the view I also don't have access to the Driver to call edit() again. I took a look at how it is done in the lists but there are too much new concepts, I don't think I have to learn all that code just to be able to handle this simple case
Thanks for you answers
Upvotes: 0
Views: 334
Reputation: 4602
Since the editor framework will work on the same object that you have delivered into the editor, you can savely add the missing parts during editing.
I think, I would try to resolve it either with the OptionalFieldEditor, or with a combination of ValueAwareEditor and Subeditors.
The main structure could be something like
public class Person implements Serializable
{
private CompanyBasicInfo companyInfo; // nullable
private PersonBasicInfo personInfo; // nullable
private String fooBar;
[ ... add getters and setters ... ]
}
The Editor will then implement at least ValueAware
public class PersonEditor implements ValueAwareEditor<Person>
{
@UiField
CompanyBasicInfoEditor companyInfo;
@UiField
PersonBasicInfoEditor personInfo;
@UiField
TextBox fooBar;
// You may not want to use this, but rather have some other handlers.
@UiField
Button btnAddPerson;
@UiField
Button btnAddCompany;
@Path("")
SimpleEditor<Person> myValue;
@Override
public void setValue(Person value) {
companyInfo.setVisible(value.getCompanyInfo() != null);
personInfo.setVisible(value.getPersonInfo() != null);
}
@UiHandler("btnAddCompany")
protected void onAddCompany(ClickEvent ev) {
CompanyBasicInfo bci = new CompanyBasicInfo();
myValue.getValue().setCompanyInfo(bci);
companyInfo.setValue(bci); // the setValue() function handles the prior unset optional field editor
}
@UiHandler("btnAddPerson")
protected void onAddPerson(ClickEvent ev) {
PersonBasicInfo bci = new PersonBasicInfo();
myValue.getValue().setPersonInfo(bci);
personInfo.setValue(bci); // the setValue() function handles the prior unset optional field editor
}
[ ... remaining stuff ... ]
}
The subeditors should be IsEditor<OptionalFieldEditor>
. You can find samples of OptionalFieldEditors on the gwtproject page, iirc.
Hope this helps you forward.
Upvotes: 1