0

How to use "apply" attribute in ZUL page

asked 2011-12-20 22:35:09 +0800

zknewbie1 gravatar image zknewbie1
370 4

Hi, I'd like to use the new "apply" attribute in the ZUL over the older "use" attribute but don't quite know how to convert the old Java code to the newer one. Attached is a quick sample. Could someone help with switching this code to be used with "apply" ? Thanks very much..

ZUL file:
======

<?xml version="1.0" encoding="UTF-8"?>
<zk xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns='http://www.zkoss.org/2005/zul'
    xmlns:h='http://www.w3.org/1999/xhtml'
    xsi:schemaLocation='http://www.zkoss.org/2005/zul WEB-INF/xsd/zul.xsd'
    >

<window id='testWin' use='GcmScLaunch.ControllerTestWin'
        border='normal' title='A Test Page'>
  
  <listbox id='testLstBox' mold="select" rows="1" 
     onCreate='testWin.testLstBox_onCreate()'
  >
  </listbox>
  
  <button id='qryShowAllSalesGroupBtn' label='Show Replies' autodisable='self'
             style='width:18ex;'
     onClick='testWin.qryShowAllSalesGroupBtn_onClick()' />

  
</window>
</zk>


Java file:
=======
package GcmScLaunch;

import java.sql.SQLException;
import javax.servlet.ServletContext;
import java.util.*;
import java.io.*;
import org.zkoss.zul.*;
import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;

/** Controller class for test.zul page */

public class ControllerTestWin extends Window {
  
  private Listbox getTestLstBox() {
    return ((Listbox) getFellow("testLstBox"));  
  }//end method   
    
  /** Controller constructor */
  public ControllerTestWin() {
    
  }//end contructor
  
  public void testLstBox_onCreate() throws Exception {
    Listbox testLstBox = this.getTestLstBox();  
    (new Listitem("Hello World!!")).setParent(testLstBox);
    testLstBox.setSelectedIndex(0);
  }//end method
  
  public void qryShowAllSalesGroupBtn_onClick() throws Exception {
    Listbox testLstBox = this.getTestLstBox();  
    testLstBox.getChildren().clear();
    testLstBox.invalidate();
    String theItem = "Hi From World";
    for(int i=0; i <= 10; i++) {
      String item = theItem + String.valueOf(i);
      (new Listitem(item)).setParent(testLstBox);
      testLstBox.setSelectedIndex(0);
    }//end for
  }//end method
  
}//end class

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2011-12-21 01:31:12 +0800

matthewgo gravatar image matthewgo
375

updated 2011-12-21 06:49:28 +0800

HI
zul:

<?xml version="1.0" encoding="UTF-8"?>
<zk>
	<window id='testWin' apply='GcmScLaunch.TestWinViewCtrl'
		border='normal' title='A Test Page'>
		<listbox id='testLstBox' mold="select" rows="1"></listbox>
		<button id='qryShowAllSalesGroupBtn' label='Show Replies'
			autodisable='self' style='width:18ex;' ></button>
	</window>
</zk>


composer:

package GcmScLaunch;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Window;

public class TestWinViewCtrl extends GenericForwardComposer {

	//private Window testWin;
	//private Button qryShowAllSalesGroupBtn;
	//private Listbox testLstBox;

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

	public void onClick$qryShowAllSalesGroupBtn(Event evt){
		//
		Listbox testLstBox = (Listbox)evt.getTarget().getFellow("testLstBox");  
	    testLstBox.getChildren().clear();
	    testLstBox.invalidate();
	    String theItem = "Hi From World";
	    for(int i=0; i <= 10; i++) {
	      String item = theItem + String.valueOf(i);
	      (new Listitem(item)).setParent(testLstBox);
	      testLstBox.setSelectedIndex(0);
	    }//end for
	}

	public void onCreate$testLstBox(Event evt){
		//
		Listbox testLstBox = (Listbox)evt.getTarget().getFellow("testLstBox");
	    (new Listitem("Hello World!!")).setParent(testLstBox);
	    testLstBox.setSelectedIndex(0);
	}

}

For more infomation please refer to the follows:
http://wiki.zkoss.org/wiki/ZK_Developer's_Reference/MVC/Controller/Composer

link publish delete flag offensive edit

answered 2011-12-21 04:36:39 +0800

zknewbie1 gravatar image zknewbie1
370 4

Thanks very much Matthewgo..

link publish delete flag offensive edit

answered 2011-12-21 21:09:20 +0800

zknewbie1 gravatar image zknewbie1
370 4

Uhhh....there's a bit of a problem, I ran the new code and the onCreate method never got executed??

link publish delete flag offensive edit

answered 2011-12-21 21:15:20 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-12-21 21:17:02 +0800

you can do that in the onCreate method of the window

public class TestWinViewCtrl extends GenericForwardComposer {
. . .
private Window testWin;
private Button qryShowAllSalesGroupBtn;
private Listbox testLstBox;

. . 
public void onCreate$testWin(Event evt){
	    (new Listitem("Hello World!!")).setParent(testLstBox);
	    testLstBox.setSelectedIndex(0);
	}

best
Stephan

link publish delete flag offensive edit

answered 2011-12-21 21:27:06 +0800

zknewbie1 gravatar image zknewbie1
370 4

Thanks Stephan. Now it works! But why can't onCreate() of the list box be called directly like the old code where the class extends Window instead of GenericForwardComposer? Also, with this new Composer class, if I want to initialize other private variables like DAO connection, Sessions, etc. should I do them inside the constructor method or inside that doAfterCompose() method ?

link publish delete flag offensive edit

answered 2011-12-21 23:26:55 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-12-21 23:48:42 +0800

//private Listbox testLstBox;

--> //

By using the GenericForwardComposer zk goes through all instance vars of the declared components to have access by naming convention. You have comment out the 'private Listbox testLstBox;' code line so the zk parser cannot see them.

best
Stephan

PS: There are a few sample applications from the contributors and there are several ways to come to goal. Look like they do such things. A good starting point for a deeper look inside such a complex app is here: http://www.zk-web.de/zksample2/
with code change history and free source codes. Thread is here.

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: 2011-12-20 22:35:09 +0800

Seen: 424 times

Last updated: Dec 21 '11

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