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

ZK 5.0 released

Finally version 5.0 of the growing popular Ajax-Web-Framework is released. Quite a number of new and updated features certainly drives up the number of users and pushes the community further. Find more information at zkoss.org. As usual the Netbeans plugin will most probably follow in a few days time. Keep you updated.

Getting started with ZK and Netbeans

In my ongoing evaluation of various web frontend frameworks, I stumbled upon the ZK Open Source Ajax (among others like IceFaces, JMaki/Dojo/Comet, JSF Controls). Even ZK appears a bit more on the Eclipse side it can easily be used in Netbans. In order to get the ZK implanted in our favorite IDE, you need to download the plugin from Sourceforge (link). Please note the startsite on ZK (SF) highlights the current version 2.0.3 from March 2009, but clicking on the download link on the right points you to the old version, so you better select the browse packages link.

Link to ZK Website
Link to SF REM 2.0.3 Plugin

Start Netbeans and open the Tools/Plugins/Downloaded and add the downloaded plugin (with the usual agree and confirm unsigned plugin dialog.

bv2009031911350016

REM 2.0.3 NB plugin

That’s it ! Welcome to ZK in Netbeans.

Start a new web project and select the ZK 360 option.

ZK360 Project

ZK360 Project

You will find a project skeleton with an initial index.zul file

ZK Project Skeleton

ZK Project Skeleton

Start the application and it gets deployed to Glassfish (or you choice of AS). So far I have no problems running it on Glassfish V2 and V3 prelude.

I run through the evaluator tutorial with ease (link).
Stay tuned for more hands-on with Netbeans and ZK.

Application Framework

Looking around for a nice browser based application framework I stumbled upon 3 opensource products that are somehow integrated into the Netbeans and Glassfish world.

  • Icefaces (Woodstock migrated here) | link
  • ZK direct RIA | link
  • JMaki / Dojo | link | link

I will evaluate these 3 and report about the results here. While Icefaces and ZK are clearly enterprise enabled frameworks, JMaki is a rather consumer application orientated framework. I might be wrong with this statement, but this is my first tast bitting on it. ZK seems closer to Spring and Tomcat than Netbeans and Glassfish.