Kathick
Kathick

Reputation: 1405

zkoss is not binding the value

My zkoss code is not binding the value from java method.

<window border="normal" id="home"
    apply="com.test.HomeController">
    <caption label="@{home.name}"></caption>
            <button label="text"></button>
</window>


public class HomeController extends GenericForwardComposer{

    public  String getName() {
        return "MY ZKOSS";
    }

}

The window caption is not showing MY ZKOSS . can any one tell me what is the issue?

Upvotes: 0

Views: 2062

Answers (3)

This may help you.

Controller:

package foo;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zul.*;

public class MyComposer extends SelectorComposer<Window> {

    @Wire
    Textbox input;
    @Wire
    Label output;

    @Listen("onClick=#ok")
    public void submit() {
        output.setValue(input.getValue());
    }
    @Listen("onClick=#cancel")
    public void cancel() {
        output.setValue("");
    }

}

And in your zul:

<window apply="foo.MyComposer">
    <div>
        Input: <textbox id="input" />
    </div>
    <div>
        Output: <label id="output" />
    </div>
    <button id="ok" label="Submit" />
    <button id="cancel" label="Clear" />
</window>

the member fields input, output are automatically assigned with components with identifiers of "input" and "output", respectively. The methods submit() and cancel() will be called when user clicks on the corresponding buttons.

http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVC/Controller/Composer#Custom_Controller

Upvotes: 0

William Cuadros
William Cuadros

Reputation: 113

ZK can use the MVVM pattern.

<window id="win" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('myController')">
     <caption label="@load(vm.myText)"></caption>
</window>


public class myController {
private String name = "MY ZKOSS";

    public  String getName() {
        return name;
    }

public  void setName(String name) {
        this.name =  name;
    }
}

ZK Developer Reference - MVVM

Upvotes: 6

kachhalimbu
kachhalimbu

Reputation: 2200

value binding through getter for a controller extending from GenericForwardComposer will work with EL expression like label="${$composer.name}"

The kind of data binding you are trying to use will work if controller is extending from component base class for eg HomeController extends from Window instead of GenericForwardComposer. For this to work change apply to use like shown below

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<window border="normal" id="home" use="com.test.HomeController">
    <caption label="@{home.name}"></caption>
    <button label="text"></button>
</window>

Upvotes: 2

Related Questions