-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a tabbox
and programmably add tabs, tab, tabpanels, and tabpanel(s) to it
Each tab must display a persons details, and allow them to be updated
I have an arraylist of Person(s) objects.
I am attempting to bind each instance in the arrayindex to a different tabpanel.
and i cannot get it to work!
All i can manage is to bind all tabpanel(s) to the last arraylist instance that i added!
i have a composer with this method
to add tabs,tab,tabpanels,tabpanel as follows:-
private int addChildrenTab() { AnnotateDataBinder tabboxBinder; Tabpanels tabpanels = null; Tabpanel tabpanel = null; Tabs tabs = null; Tab tab = new Tab(); tab.setSelected(true); int childIndex = 0; Map<String,Integer> arguments = new HashMap<String, Integer>(); if (childrenTabbox.getTabs() == null){ tabpanels = new Tabpanels(); tabs = new Tabs(); childrenTabbox.appendChild(tabs); childrenTabbox.appendChild(tabpanels); } else { tabpanels = childrenTabbox.getTabpanels(); tabs = childrenTabbox.getTabs(); childIndex = tabs.getChildren().size(); } arguments.put("tabularIndex", childIndex); childrenTabbox.getTabs().appendChild(tab); tabpanel = (Tabpanel)Executions.createComponents("childTabPanel.zul", tabpanels, arguments); childrenTabbox.getTabpanels().appendChild(tabpanel); childrenTabbox.invalidate(); tabboxBinder = new AnnotateDataBinder(childrenTabbox); tabboxBinder.loadAll(); return tab.getIndex(); }
part of childTabPanel.zul looks like this
and as i create each new Tab and its children components the correct arraylist instance is
displayed
however as i click on previous tabs they now show only the most recently bound arraylist instance
what am i doing wrong?
<?xml version="1.0" encoding="UTF-8" ?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <zk> <zscript><![CDATA[ com.pre.school.dao.Person myChild = family.getChild(arg.get("tabularIndex")); System.out.println("in zscript " + myChild.getFirstName()); ]]> </zscript> <tabpanel id="daniel${arg.tabularIndex}"> <grid fixedLayout="false"> <columns> <column label="" width="15%" /> <column label="" width="30%" /> </columns> <rows> <row> <label value="Gender" /> <combobox model="@{preSchoolReferenceData.genders}" selectedItem="@{myChild.gender}" readonly="true" mold="rounded"> <comboitem self="@{each='childGender'}" label="@{childGender.description}"> </comboitem> </combobox> </row> <row> <label value="First Name" width="100px" /> <textbox constraint="no empty" value="@{myChild.firstName, save-when='self.onBlur'}" width="190px" /> </row>
As no one in the forum is going to help me i'll help myself...
the problem is caused by each tabpanel having the same named java Person variable myChild
if i create a different zul page for each tabpanel and use create components on that
tabpanel = (Tabpanel)Executions.createComponents("childTabPanel.zul", tabpanels, arguments);
then
tabpanel = (Tabpanel)Executions.createComponents("childTabPanel1.zul", tabpanels, arguments);
and so on ...
tabpanel = (Tabpanel)Executions.createComponents("childTabPanel<b >N</b>.zul", tabpanels, arguments);
the data binding on each tabpanel works fine...
So i need a "clean" way to build new zul pages dynamically. does anybody have any experience of this please?
I think the way to go is read in the basic zul file and repeatedly build Documents from it having already changed the
name of the myChild Person variable...
unless there is another way to isolate/scope java variables in multiple zul pages that have the same name.
why is zk making common named java variables in zscript refer to the same java object when they are initially assigned
completely different instances?
Thanks in advanced
DD
henrichen
thanks for looking at this
thats what i have done but its messy and i was trying to follow DRY!
Oh Well
DD
Asked: 2010-04-23 10:30:50 +0800
Seen: 298 times
Last updated: Apr 27 '10