0

use of zk6.0.1 @ref feature

asked 2012-05-07 14:01:18 +0800

simonmassey gravatar image simonmassey
90 1

I am trying to apply the reference binding feature to this page of the zktodo2 demo app supervisingcontroller.zul

In that page the viewmodel is called "c" but all the data is in "c.model". So I want to do something like

<window apply="org.zkoss.bind.BindComposer" viewModel="@id('c') @init('org.zkforge.zktodo2.ui.Controller')">
		<vlayout bm="@ref(c.model)">
			<listbox
				model="@load(bm.reminders)" 
				selectedItem="@bind(bm.selectedReminder)">

in that I am trying to @ref the "c.model" to the property "bm" then use "bm.reminders" and "bm.selectedReminder" to draw the page. I cannot get this to work with the current version of the sample code. What is the correct way to use @ref in this example?

Thanks,

Simon

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-05-10 02:10:36 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2012-05-10 02:11:37 +0800

Hi Simon,

I checked your source code from git repository. And here is my sample code modified from your origin code that works fine.
zul page:

<window title="ZkTodo2 - Supervising Controller" width="640px" border="normal" 
    apply="org.zkoss.bind.BindComposer"
    viewModel="@id('c') @init('forum.ControllerVM')">
    <vlayout bm="@ref(c.model)">
        <listbox
            model="@bind(bm.reminders)"
            selectedItem="@bind(bm.selectedReminder)">

ControllerVM.java
public class ControllerVM {
    // wired property     
    @WireVariable Model model = null; 

    public void setModel(Model model) { this.model = model; }
    public Model getModel() { return model; }

    @Init
    public void init(@ContextParam(ContextType.VIEW) Component view){
        Selectors.wireComponents(view, this, false);
        model = new Model();
        reload();
    }

    protected void reload() {
        List<Reminder> reminders = new ArrayList<Reminder>();
        reminders.add(new Reminder("event1", 2, new Date()));
        reminders.add(new Reminder("event2", 1, new Date()));
        reminders.add(new Reminder("event3", 3, new Date()));
        reminders.add(new Reminder("event4", 1, new Date()));
        reminders.add(new Reminder("event5", 4, new Date()));
        this.model.getReminders().clear();
        this.model.getReminders().addAll(reminders);
    }

link publish delete flag offensive edit

answered 2012-05-13 06:30:59 +0800

simonmassey gravatar image simonmassey
90 1

Using your example I get the following error:

org.zkoss.zk.ui.UiException: ref binding handler is not supported in current runtime.
at org.zkoss.bind.impl.BinderImpl.addReferenceBinding0(BinderImpl.java:1086)
at org.zkoss.bind.impl.BinderImpl.addReferenceBinding(BinderImpl.java:1074)
at org.zkoss.bind.impl.AnnotateBinderHelper.processReferenceBinding(AnnotateBinderHelper.java:229)
at org.zkoss.bind.impl.AnnotateBinderHelper.processPropertyBindings(AnnotateBinderHelper.java:201)
at org.zkoss.bind.impl.AnnotateBinderHelper.processComponentBindings0(AnnotateBinderHelper.java:103)
at org.zkoss.bind.impl.AnnotateBinderHelper.processAllComponentsBindings(AnnotateBinderHelper.java:78)
at org.zkoss.bind.impl.AnnotateBinderHelper.processAllComponentsBindings(AnnotateBinderHelper.java:81)
at org.zkoss.bind.impl.AnnotateBinderHelper.initComponentBindings(AnnotateBinderHelper.java:68)
at org.zkoss.bind.AnnotateBinder.init(AnnotateBinder.java:49)
at org.zkoss.bind.BindComposer.doAfterCompose(BindComposer.java:136)

I am running as "mvn jetty:run" on Mac OS Lion using

java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3646)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)

and maven3.0.3.

I have committed your sample code which shows my error as test.zul

link publish delete flag offensive edit

answered 2012-05-14 10:59:05 +0800

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

Hi, Simon
@ref is new in zk 6.0.1 and you need PE(or EE) version to use @ref feature.

/Dennis

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-05-07 14:01:18 +0800

Seen: 318 times

Last updated: May 14 '12

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