Doubt about using ValueListBox + UIBinder + Editors Framework

433 views
Skip to first unread message

vehdra music

unread,
Jul 19, 2011, 5:42:06 PM7/19/11
to Google Web Toolkit
Hi, I have two beans:

public class User implements IsSerializable {
...
private companyId; // fk to companies
...
}

and:


public class Company implements IsSerializable {
...
private Long id;
private String name;
...
}

This is my UI Code:

<g:ValueListBox ui:field="companyId"></g:ValueListBox>

And this is my Java code for my ValueListBox:

@UiField(provided = true) ValueListBox<Company> companyId = new
ValueListBox<Company>(new Renderer<Company>() {

@Override
public String render(Company object) {
// TODO Auto-generated method stub
return object != null ? object.getName() : "";
}

@Override
public void render(Company object, Appendable appendable) throws
IOException {
// TODO Auto-generated method stub
}
});

How can I do to fill the User.companyId value when I do user =
driver.flush(); ?

Another question that I have about ValueListBox is how can I render
each item by pairs of value / text? I mean, something like <option
value="8">Company x</option><option value="10">Company Y</option>

Thanks in advance.

Thomas Broyer

unread,
Jul 19, 2011, 6:18:35 PM7/19/11
to google-we...@googlegroups.com
Given that User#companyId is a Long (I guess), you have to use some kind of Editor<Long> (or an IsEditor of some kind of Editor<Long>), which ValueListBox<Company> obviously isn't.
You can make it work by not using ValueListBox as an editor (@Editor.Ignore) and instead implement ValueAwareEditor<User> on the parent: explicitly select the company from companyId in setValue, and update companyId from the selected Company in flush(). As an alternative, you can use a simple LeafValueEditor<Long> for the companyId, that would do the same (forward to the ValueListBox) in its setValue and getValue.

As for your second question, well, don't use ValueListBox then; use a ListBox instead and manually add items.

Sebastian Carrizo

unread,
Aug 11, 2011, 9:45:00 PM8/11/11
to google-we...@googlegroups.com
Hi, i have the same problem, do you have a class documentation link or some kind of documentation about LeafValueEditor? i only could get a description.


Thanks
Reply all
Reply to author
Forward
0 new messages