0

ZK 6 bind and model:group

asked 2012-04-27 07:40:52 +0800

khcyt gravatar image khcyt
216 1 1

Hello,

If i use EL-expressions, the model:group works as expexted and described in documentation.

<zk>
    <zscript><![CDATA[
        String[][] datas = new String[][] 
        {
            new String[] 
            {   //group 1, Today
                "RE: Bandbox Autocomplete Problem",
                "RE: It's not possible to navigate a listbox' ite",
                "RE: FileUpload"
            },
            new String[] 
            {   //group 2, Yesterday
                "RE: Opening more than one new browser window",
                "RE: SelectedItemConverter Question"
            },
            new String[] 
            {   //group 3, Last Week
                "RE: Times_Series Chart help",
                "RE: SelectedItemConverter Question"
            }           
        };
        GroupsModel fooGroupsModel= new SimpleGroupsModel(datas, new String[]{"Date: Today", "Date: Yesterday", "Date: Last Week"});
	]]></zscript>

	<window id="win" title="Window 1" border="normal" width="600px">
		<listbox model="${fooGroupsModel}">
		   <template name="model:group">
		      <listgroup open="${groupingInfo.open}" label="${each}"/>
		   </template>
		   <template name="model">
		      <listitem>
		      	<listcell label="${each}"/>
		      </listitem>
		   </template>
		</listbox>
    </window>
</zk>

So far, so good.
How can i achieve this behaviour with the new ZK6 bind mechanism? The code below does not interpret model:group corrrectly.

<zk>
    <zscript><![CDATA[
        String[][] datas = new String[][] 
        {
            new String[] 
            {   //group 1, Today
                "RE: Bandbox Autocomplete Problem",
                "RE: It's not possible to navigate a listbox' ite",
                "RE: FileUpload"
            },
            new String[] 
            {   //group 2, Yesterday
                "RE: Opening more than one new browser window",
                "RE: SelectedItemConverter Question"
            },
            new String[] 
            {   //group 3, Last Week
                "RE: Times_Series Chart help",
                "RE: SelectedItemConverter Question"
            }           
        };

        class VM
        {
            GroupsModel fooGroupsModel= new SimpleGroupsModel(datas, new String[]{"Date: Today", "Date: Yesterday", "Date: Last Week"});

            public GroupsModel getGroupsModel()		{ return fooGroupsModel; } 
        }
	]]></zscript>

	<window id="win" title="Window 1" border="normal" width="600px" 
    		apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('VM')" >
    		    	
		<listbox model="@bind(vm.groupsModel)">
		   <template name="model:group">
		      <listgroup open="@bind(groupingInfo.open)" label="@load(each)"/>
		   </template>
		   <template name="model">
		      <listitem>
		      	<listcell label="@load(each)"/>
		      </listitem>
		   </template>
		</listbox>
    </window>
</zk>

Further questions is, how can i combine ZK 6 bind syntax with extended capabilities, such as possible with conventional EL expressions?

works <listcell><label value="${c:cat3('[', each, ']')}"/></listcell>
not works <listcell><label value="@load(c:cat3('[', each, ']'))"/></listcell>

Kai

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-06-12 11:25:16 +0800

khcyt gravatar image khcyt
216 1 1

I have tested this code in ZK Fiddle with ZK 6.0.1 and now the group information correctly interpreted. However, the group label is still not shown. I suspect that "each" at the time of evaluating an object of type ReferenceBindingImpl.

Kai

link publish delete flag offensive edit

answered 2012-06-12 14:03:51 +0800

iantsai gravatar image iantsai
2755 1

I don't think current zul annotation support this approach:
<listcell><label value="@load(c:cat3('[', each, ']'))"/></listcell>

Have you take a look at this example yet?
http://www.zkoss.org/zkdemo/grid/grouping_model

link publish delete flag offensive edit

answered 2012-06-13 08:01:56 +0800

khcyt gravatar image khcyt
216 1 1

If I use the SimpleGroupsModel with a grid, as shown in the example, everything works without problems.
Only the groups in listbox will not display correctly. It is also thrown an IllegalArgumentException

>>org.zkoss.zel.ELException: java.lang.IllegalArgumentException
>>java.lang.IllegalArgumentException
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at org.zkoss.zel.BeanELResolver.setValue(BeanELResolver.java:139)
>> at org.zkoss.zel.CompositeELResolver.setValue(CompositeELResolver.java:83)
>> at org.zkoss.zel.CompositeELResolver.setValue(CompositeELResolver.java:83)
>> at org.zkoss.xel.zel.XelELResolver.setValue(XelELResolver.java:114)
>> at org.zkoss.bind.xel.zel.BindELResolver.setValue(BindELResolver.java:102)
>> at org.zkoss.zel.impl.parser.AstValue.setValue(AstValue.java:215)
>> at org.zkoss.zel.impl.ValueExpressionImpl.setValue(ValueExpressionImpl.java:256)
>> at org.zkoss.xel.zel.ELXelExpression.setValue(ELXelExpression.java:50)
>> at org.zkoss.bind.impl.BindEvaluatorXImpl.setValue(BindEvaluatorXImpl.java:50)
>> at org.zkoss.bind.impl.LoadPropertyBindingImpl.load(LoadPropertyBindingImpl.java:81)
>> at org.zkoss.bind.impl.PropertyBindingHandler.doLoadBinding(PropertyBindingHandler.java:171)
>> at org.zkoss.bind.impl.PropertyBindingHandler.doLoad(PropertyBindingHandler.java:372)
>> at org.zkoss.bind.impl.BinderImpl.loadComponentProperties(BinderImpl.java:1865)
>> at org.zkoss.bind.impl.BinderImpl.loadComponent(BinderImpl.java:1847)
>> at org.zkoss.bind.tracker.impl.BindUiLifeCycle$1.onEvent(BindUiLifeCycle.java:63)
>> at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2736)
>> at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2685)
>> at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2648)
>> at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
>> at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1702)
>> at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1487)
>> at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:463)
>> at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:316)
>> at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:215)
>> at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:135)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
>> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
>> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
>> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
>> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
>> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
>> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
>> at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
>> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
>> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
>> at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
>> at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
>> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>> at java.lang.Thread.run(Thread.java:619)

Kai

link publish delete flag offensive edit

answered 2012-06-22 03:59:25 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

updated 2012-06-22 04:02:29 +0800

this is a bug, groupInfo is not supported yet in bind , and the exception was cause by assign a NULL (groupingInfo.open) to a primitive boolean type .

I posted a bug at http://tracker.zkoss.org/browse/ZK-1207, please follow it if you want.

link publish delete flag offensive edit

answered 2012-06-22 11:24:02 +0800

khcyt gravatar image khcyt
216 1 1

OK thank you Dennis, now I know about this error. In the meantime, I avoid the problem by using dynamic templates.

Kai

<zk>
    <zscript><![CDATA[
        ListModel lm= new ListModelList();
        
		
	class A
        {
            public A(String s, Long v, Boolean is_group)	{ s_= s; v_= v; is_group_= is_group; }
            
            public String getData()			{ return s_; }
            public Boolean isGroup()		{ return is_group_; }
            public Long getValue()			{ return v_; }

            String s_= null;
            Long v_= null;
	    Boolean is_group_= null;
        }
		
		lm.add(new A("Today", 1L, Boolean.TRUE));
		lm.add(new A("RE: Bandbox Autocomplete Problem", 2L, Boolean.FALSE));
		lm.add(new A("RE: It's not possible to navigate a listbox' ite", 3L, Boolean.FALSE));
		lm.add(new A("RE: FileUpload", 4L, Boolean.FALSE));

		lm.add(new A("Yesterday", 10L, Boolean.TRUE));
		lm.add(new A("RE: Opening more than one new browser window", 11L, Boolean.FALSE));
		lm.add(new A("RE: SelectedItemConverter Question' ite", 12L, Boolean.FALSE));

		lm.add(new A("Last week", 100L, Boolean.TRUE));
		lm.add(new A("RE: Times_Series Chart help", 101L, Boolean.FALSE));
		lm.add(new A("RE: SelectedItemConverter Question", 102L, Boolean.FALSE));

        class VM
        {
            public ListModel getListModel()		{ return lm; } 
        }
	]]></zscript>

	<window id="win" title="Window ZK6 dynamic template" border="normal" width="600px" 
    		apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('VM')" >    		    	
		<listbox model="@bind(vm.listModel) @template(each.isGroup() ? 'group_model' : 'item_model')">
			<listhead>
				<listheader hflex="2" label="Column 1"/>
				<listheader hflex="1" label="Column 2"/>
			</listhead>
			<template name="group_model">
				<listgroup open="true" label="@load(each.data)"/>
			</template>
			<template name="item_model">
				<listitem vflex="1">
					<listcell><label value="@load(each.data)"/></listcell>
					<listcell><label value="@load(each.value)"/></listcell>
				</listitem>
			</template>
		</listbox>
    </window>
</zk>

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: 2012-04-27 07:40:52 +0800

Seen: 555 times

Last updated: Jun 22 '12

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