-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
.
I have a page using the new zk6 databinding feature, it contains a listbox and a viewmodel class.
The problem is when I use the viewmodel class to create a new database entity row,
the page will update all the entity content to the entity which I just created (only view, the origin entities in listmodel is fine).
For example, I have a list of entities with id 1 to 5, then I create a new entity id=6,
the page with automatic update all the entity content in the listbox to the entity[id=6]
only the content on the page is changed, everything else (include the entities in listModel) remains original.
And if the listbox has more than one page, it won't update all the entities to the newest entity until the newest entity is showed.
Any idea? Thank you.
here is the example of my viewmodel
public class ViewModel{ private ListModelList listModel; private Entity selectedEntity; private EntityDao dao; public ViewModel() { EntityDao dao = new EntityDao(); listModel = new ListModelList(dao.list()); } public Entity getSelectedEntity() { return selectedEntity; } @NotifyChange({"selectedEntity"}) public void setSelectedEntity(Entity selectedEntity) { this.selectedEntity = selectedEntity; } public boolean createEntity(Entity entity) { EntityDao dao = new EntityDao(); boolean isSuccess = dao.create(entity); if (isSuccess) { listModel.add(eneity); return true; } else { return false; } } public ListModelList getListModel() { return listModel; } @NotifyChange({"listModel"}) public void setListModel(ListModelList listModel) { this.listModel= listModel; } }
my listbox snippet
<window apply="org.zkoss.bind.BindComposer" vflex="true" viewModel="@id('vm') @init('ViewModel'))"> <listbox id="list" model="@load(vm.listModel)" selectedItem="@bind(vm.selectedEntity)" hflex="true" mold="paging" multiple="false" checkmark="true" autopaging="true"> <listhead> <listheader hflex="min"></listheader> <listheader label="ID" hflex="min" sort="auto(id)"></listheader> </listhead> <template name="model" var="entity"> <listitem value="@bind(entity)"> <listcell></listcell> <listcell> <intbox value="@bind(entity.id)" inplace="true" constraint="no empty,no negative,no zero" width="120px"></intbox> </listcell> </listitem> </template> </listbox> </window>
my create entity snippet
<button label="Save Entity"> <attribute name="onClick"> <![CDATA[ Entity entity = new Entity(); //skipped, get the entity information from a form boolean isSuccess = vm.createEntity(entity); //skipped, post process. ]]> </button>
Asked: 2012-01-31 06:03:10 +0800
Seen: 224 times
Last updated: Feb 02 '12