Code Snippet: ZK controller reading URL parameter

How to pass parameters as part of the URL like http://….?name=Smith&first=John ?

ZUL page

<pre><?xml version="1.0" encoding="UTF-8"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
    <window id="index" apply="controller.indexController" >
        <label value="Parameter 1:"/>
        <label id="lblPar1" />
        <label value=" - Parameter 2:"/>
        <label id="lblPar2" />
    </window>
</zk>

Controller

package controller;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Label;

public class indexController extends GenericForwardComposer {

    private Label lblPar1;
    private Label lblPar2;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);

        if (Executions.getCurrent().getParameter("parameter1") != null) {
            String par = Executions.getCurrent().getParameter("parameter1");
            lblPar1.setValue(par);
        } else {
            lblPar1.setValue("null");
        }
        if (Executions.getCurrent().getParameter("parameter2") != null) {
            String par = Executions.getCurrent().getParameter("parameter2");
            lblPar2.setValue(par);
        } else {
            lblPar2.setValue("null");
        }
    }
}

SVH20121203001

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s