0

Model-driven Listboxes

asked 2010-07-19 10:49:06 +0800

twiegand gravatar image twiegand
1807 3

Hello everyone,

We seem to be having trouble getting things like listitems in a model-driven listbox to interact with other ZK elements in a normal way. For example, when we try to set a listitem's value or find its parent window, we run into difficulties.

Please consider the following code:

<?variable-resolver class="org.zkoss.zkplus.jndi.JndiVariableResolver" ?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>

<zk>
	<zscript>
		import org.zkoss.zk.ui.util.*;
	
		public class Provider {
			private String providerName;

			public Provider(String pn) {
				setProviderName(pn);
			}

			public String getProviderName() {
				return providerName;
			}
			public void setProviderName(String pn) {
				providerName = pn;
			}

		}

		List Providers = new ArrayList();
		Providers.add(new Provider("providerName1"));
		Providers.add(new Provider("providerName2"));
		Providers.add(new Provider("providerName3"));

		Provider outsideProvider = new Provider("providerNameOutside");

		public class aZKLabelConvert extends org.zkoss.zul.Label {
			public void onCreate() {
				hasParentWindow();					
			}	
			
			// Why does this cause the list box to not show values but has no affect on the labels outside of the list
			// just delete and the list box will show the names of the providers

			public void setValue(String value){
				super.setValue(value);
				hasParentWindow();
			}
			
			// Why can't the items in the listbox get to the parent window?

			private void hasParentWindow(){
				Component comp = this;
				while (comp != null && !(comp.getAttribute("composer") != null) && !(comp.getAttribute("composer") instanceof ManagementDetailComposer)) {
					System.out.println(comp);
					comp = comp.getParent();										
				}
				if (comp == null) {
					System.out.println("Could not find composer");
				} else {
					System.out.println(comp + " -- " + comp.getAttribute("composer"));
				}	
			}
			
		}	
			
		public class ManagementDetailComposer extends GenericAutowireComposer {
			public void doAfterCompose(Component comp) throws Exception {
				super.doAfterCompose(comp);

				comp.setAttribute("composer", this);
				page.setAttribute(comp.getId() + "Composer", this, true);
			}
		}
		
	</zscript>

	<window id="winId" width="100%" apply="ManagementDetailComposer" vflex="false" >
		<listbox fixedLayout="true" mold="paging" model="@{Providers}"  height="140px">
			<listhead>
				<listheader label="Provider"/>
			</listhead>
			<listitem self="@{each=aProvider}">
				<listcell> 
					<label value="@{aProvider.providerName}" use="aZKLabelConvert" />
				</listcell>
			</listitem>
		</listbox>
		<label id="outsidelabel" value="@{outsideProvider.providerName}" use="aZKLabelConvert" />
	</window>
</zk>

We need to be able to programmatically set the value, override z-class, etc for listitems. What are we doing wrong? Should we be using a renderer? If so, is there an example (with binding) that we could utilize?

Thank you very much for your help!

Todd

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-07-28 22:12:16 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Can you try on the latest ZK freshly version? The onCreate is not called in old version until recently when used with data binding and lisitbox/grid.

link publish delete flag offensive edit

answered 2010-07-29 12:24:50 +0800

twiegand gravatar image twiegand
1807 3

updated 2010-07-29 12:25:24 +0800

I tried Freshly 5.0.4 EE but it doesn't seem to exhibit any different behavior. We are currently running 5.0.3 EE.

What should we try next?

Thanks for all your help,

Todd

link publish delete flag offensive edit

answered 2010-07-29 14:54:56 +0800

Matze2 gravatar image Matze2
773 7

If you use data binding, I would perform the changes on the model and then force a data binding refresh (DataBinder.loadAll).
If you just call setValue on the label directly, the model does not get updated and you have inconsistencies.

Regarding the second question, why can't you get to the parent window, I don't know. I would try to debug it.

If you would also set the value attribute in your listitem:
<listitem self="@{each=aProvider}" value="@{aProvider}">
then you may not need to traverse up to the composer again because there is the provider object in listitem already.

Maybe this helps.

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-07-19 10:49:06 +0800

Seen: 264 times

Last updated: Jul 29 '10

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