org.zkoss.spring.util
Class GenericSpringComposer

java.lang.Object
  extended by org.zkoss.spring.util.GenericSpringComposer
All Implemented Interfaces:
org.zkoss.zk.ui.event.EventListener, org.zkoss.zk.ui.util.Composer, org.zkoss.zk.ui.util.ComposerExt

public class GenericSpringComposer
extends java.lang.Object
implements org.zkoss.zk.ui.util.Composer, org.zkoss.zk.ui.util.ComposerExt, org.zkoss.zk.ui.event.EventListener

An abstract composer that you can extend and write intuitive @EventHandler("myComponent.onXXX") event handler methods and auto-wired components in a ZK ZUML page. This class will add forward condition to myComponent and forward source onXXX event received by teh source myComponent to the target component method annotated with (@link EventHandler) annotation.

Notice that since this composer kept references to the components, single instance object cannot be shared by multiple components.

The following is an example. The onClick event received by Button will be forwarded to target Window myWin and the Textbox component with id name and Button component with id greetBtn are injected into name and greetBtn fields respectively (so you can use name and greetBtn variables directly in showGreeting without problem)


 GreetingCtrl.java
 @org.springframework.stereotype.Component ("greetingCtrl")
 @Scope ("desktop")
 public class GreetingCtrl extends GenericSpringComposer {

                @Autowired private Textbox name;
                @Autowired private Button greetBtn;
        
        @EventHandler("greetBtn.onClick")
                public void showGreeting(Event evt) throws WrongValueException, InterruptedException {
                        Messagebox.show("Hello " + name.getValue() + "!");
                }
 }
 
 test.zul
 
 <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
 <window id="myWin" apply="${greetingCtrl}">
                <textbox id="name" />
                <button id="greetBtn" label="Greet!" />
 </window>

 

Since:
3.0
Author:
ashish

Constructor Summary
GenericSpringComposer()
           
 
Method Summary
 void addForward(java.lang.reflect.Method md, java.lang.annotation.Annotation a, org.zkoss.zk.ui.Component comp)
          method to add forward event from child component to parent or composer component
 void addForwards(org.zkoss.zk.ui.Component comp, java.lang.Object controller)
          forwards component events to controller methods annotated with Events qualifier
 void doAfterCompose(org.zkoss.zk.ui.Component comp)
          Auto-wires ZK Components in controllers and registers event handlers for
 org.zkoss.zk.ui.metainfo.ComponentInfo doBeforeCompose(org.zkoss.zk.ui.Page page, org.zkoss.zk.ui.Component parent, org.zkoss.zk.ui.metainfo.ComponentInfo compInfo)
           
 void doBeforeComposeChildren(org.zkoss.zk.ui.Component comp)
           
 boolean doCatch(java.lang.Throwable ex)
           
 void doFinally()
           
protected  java.lang.Object getController()
           
 void onEvent(org.zkoss.zk.ui.event.Event event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericSpringComposer

public GenericSpringComposer()
Method Detail

doAfterCompose

public void doAfterCompose(org.zkoss.zk.ui.Component comp)
                    throws java.lang.Exception
Auto-wires ZK Components in controllers and registers event handlers for

Specified by:
doAfterCompose in interface org.zkoss.zk.ui.util.Composer
Throws:
java.lang.Exception

getController

protected java.lang.Object getController()

doBeforeCompose

public org.zkoss.zk.ui.metainfo.ComponentInfo doBeforeCompose(org.zkoss.zk.ui.Page page,
                                                              org.zkoss.zk.ui.Component parent,
                                                              org.zkoss.zk.ui.metainfo.ComponentInfo compInfo)
                                                       throws java.lang.Exception
Specified by:
doBeforeCompose in interface org.zkoss.zk.ui.util.ComposerExt
Throws:
java.lang.Exception

doBeforeComposeChildren

public void doBeforeComposeChildren(org.zkoss.zk.ui.Component comp)
                             throws java.lang.Exception
Specified by:
doBeforeComposeChildren in interface org.zkoss.zk.ui.util.ComposerExt
Throws:
java.lang.Exception

doCatch

public boolean doCatch(java.lang.Throwable ex)
                throws java.lang.Exception
Specified by:
doCatch in interface org.zkoss.zk.ui.util.ComposerExt
Throws:
java.lang.Exception

doFinally

public void doFinally()
               throws java.lang.Exception
Specified by:
doFinally in interface org.zkoss.zk.ui.util.ComposerExt
Throws:
java.lang.Exception

onEvent

public void onEvent(org.zkoss.zk.ui.event.Event event)
             throws java.lang.Exception
Specified by:
onEvent in interface org.zkoss.zk.ui.event.EventListener
Throws:
java.lang.Exception

addForwards

public void addForwards(org.zkoss.zk.ui.Component comp,
                        java.lang.Object controller)
forwards component events to controller methods annotated with Events qualifier

Parameters:
comp -
controller -

addForward

public void addForward(java.lang.reflect.Method md,
                       java.lang.annotation.Annotation a,
                       org.zkoss.zk.ui.Component comp)
method to add forward event from child component to parent or composer component

Parameters:
md - method annotated with EventHandler annotation
a - EventHandler Annotation on md method
comp -


Copyright © 2005-2007 Potix Corporation. All Rights Reserved.