0

why cant you set ArrayList Index in seperate Tabpanel(s)?

asked 2010-04-23 10:30:50 +0800

dickdastardly gravatar image dickdastardly
168 1 5

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>

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-04-24 02:11:02 +0800

dickdastardly gravatar image dickdastardly
168 1 5

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

link publish delete flag offensive edit

answered 2010-04-26 21:47:18 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

This is a BeanShell issue (The tech behind the zscript). You might want to embed the "wisdom" of picking right child inside your getter Java code.

link publish delete flag offensive edit

answered 2010-04-27 12:01:46 +0800

dickdastardly gravatar image dickdastardly
168 1 5

henrichen

thanks for looking at this

thats what i have done but its messy and i was trying to follow DRY!

Oh Well

DD

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-04-23 10:30:50 +0800

Seen: 298 times

Last updated: Apr 27 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More