-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi :
zul snippet :
<listbox id="lbCategory" width="350px" multiple="true" checkmark="true" rows="4" selectedItems="@{applicant.applicantGroup}"/>
The model :
private transient Set<MasterApplicantGroup> applicantGroup; public Set<MasterApplicantGroup> getApplicantGroup() { return applicantGroup; } public void setApplicantGroup(Set<MasterApplicantGroup> applicantGroup) { this.applicantGroup = applicantGroup; }
In my controller when I do binder.loadAll() it gives me a Nullpointer exception. If applicantGroup is initalized then the null pointer goes away but binder.saveAll() doesn't have the selectedItems in it.
What wrong am I doing?
regards
Devinder
Because your listbox didn't contain anything.
And I'm not sure that Annotated Databinding support multiple selection in listbox.
If your requirement need to do a lot of detail control of Listbox, then using Model + renderer would be safety.
Sometimes it's better to choose the folksy approach.
Thanks for the reply.
>>Because your listbox didn't contain anything.
I have it, both model and renderer are set in the controller.
public void onCreate$applicantWindow() { try { lbCategory.setModel(new ListModelList(ApiManager.getMasterGroupDao().readAllMasterGroup())); lbCategory.setItemRenderer(new SimpleListboxRenderer()); applicant = (MasterApplicant) params.get("applicant"); binder = new AnnotateDataBinder(this); binder.bindBean("applicant", applicant); binder.loadAll(); } catch (DAOException ex) { log.error("onCreate$applicantWindow : "+ex.getMessage()); } }
To make it work I have taken away the selectedItems="@{applicant.applicantGroup}" from the list box and set the bean value manually (using getSelecteItems()). My question remains how do I get the values using annotation?
regards
Devinder
Thanks for the reply.
No. "applicant" is an instance of "MasterApplicant"
applicant = (MasterApplicant) params.get("applicant");
In MasterApplicant (my model) I have a class variable :
private transient Set<MasterApplicantGroup> applicantGroup;
<listbox id="lbCategory" width="350px" multiple="true" checkmark="true" rows="4" selectedItems="@{applicant.applicantGroup}"/>
Is there something that I am missing?
regards
Devinder
Finally I have checked the Javadoc, and now I sorry say: "you can't make it in this approach."
because there's no "setSelectedItems(Set selected)" method in listbox!
So now the way to do your job is control it all by your self. In this complex situation I think we should forget Annotated Databinding.
This technology doesn't feet this situation.
public void onCreate$applicantWindow() { try { ListModelList groupModel = new ListModelList(ApiManager.getMasterGroupDao().readAllMasterGroup()); lbCategory.setModel(groupModel ); lbCategory.setItemRenderer(new SimpleListboxRenderer()); applicant = (MasterApplicant) params.get("applicant"); Listitem item; for(MasterApplicantGroup group : applicant.getApplicantGroup()){ item = lbCategory.getItemAtIndex(groupModel.indexOf(group)) lbCategory.addItemToSelection(item); } } catch (DAOException ex) { log.error("onCreate$applicantWindow : "+ex.getMessage()); } }
Multiple databinding with annotations is only available with an own converter.
The user dasultz has written one.
<listbox id="lbCategory" width="350px" multiple="true" checkmark="true" rows="4" selectedItems="@{applicant.applicantGroup, converter=daslutz.magiccode}"/>
Check this thread.
Post if you have any troubles - i do not need multiple selection until now... so i have not testet the code. But user dasultz seems to be a poweruser, so i think the code shoudl work.
Or use the non-databinding-way as descriped by Iantsai.
/Robert
Thanks guys for the reply.
Iantsai, there is a setSelectedItems method in listbox which accepts set (since 3.6.0, a new addition I guess)
public void setSelectedItems(java.util.Set listItems)
which is why my model variable is a set.
private transient Set<MasterApplicantGroup> applicantGroup;
I was thinking a mere selectedItems="@{applicant.applicantGroup} should work. I will also to look into the Dasulz's approach of converter, as suggested by Robert.
I am already using manual approach as you too suggested, but would definitely like to see the annotation working.
regards
Devinder
Solution provided by robertpic71 won't work because the listbox doesn't update the selectedItems wen items are selected.
And the converter fails sometimes wen listbox has listhead's or other different child components.
Also,
public void setSelectedItems(java.util.Set listItems)
Asked: 2009-04-16 12:11:37 +0800
Seen: 3,740 times
Last updated: Jul 01 '10