-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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>
Thank you very much for your help!
Todd
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
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.
Asked: 2010-07-19 10:49:06 +0800
Seen: 264 times
Last updated: Jul 29 '10