0

passing parameter between zul file

asked 2007-09-02 04:28:59 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4496832

By: andy-susanto

hai,

i read a devguide. but i still do not understand how to do it ?, what i know that must use a macro file.

is anyone will help me to provide an example ? i need that because i do not want the parameter exist on the url


TIA,

andy susanto

delete flag offensive retag edit

14 Replies

Sort by ยป oldest newest

answered 2007-09-02 09:09:10 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4496968

By: rudi_black

hi andi,

to my knowledge... when we make a macro component (it can be made by zul, zs script or compiled java class), it will then act as a new component.
to my knowledge, the macro component based on zul (xml file) offer a quick result but less flexy due to the xml cant have any logical procedures. to do so, each zul file has to have a script file (zs) or we can include that script to the zul file.

as for me.. after months playing zk, i choose to use the compiled java instead.

as for passing the parameters, zk does not communicate via url.. instead, it use the component's id (in zul case) or the component it self (java approach).

for more specific cases... pls submit part of your sample in the forum so we can learn each other..

good luck.. selamat mempergunakan zk :)

-rudi-

link publish delete flag offensive edit

answered 2007-09-02 15:40:21 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4497210

By: andy-susanto

hai Rudi,

i am glad to see you.

this my code

<toolbarbutton id="${each.itemno}" label="${each.itemno}" forEach="${item}"
style="font:30px/1.2em Arial, Verdana, sans-serif;"/>

i render dynamic to show itemno that i have. when user click itemno i will show entry from to edit that.

how can i use java code if my "id" is dynamic to ?

Rudi ada email yang langsung tidak ?


TIA,

andy susanto

link publish delete flag offensive edit

answered 2007-09-02 17:06:20 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4497294

By: rudi_black

hi again andi...

i've made a new yahoo messenger account if u want to reach me... it is zk_rudi

-rudi-

link publish delete flag offensive edit

answered 2007-09-03 01:21:11 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4497688

By: jumperchen

Hi Andy,

1)You can use the following example to pass your parameter between zul files.

<zscript>
Executions.getCurrent().setAttribute("key1", "val1"); Executions.getCurrent().forward("/other.zul");
</zscript>

2)Try the following example,

<toolbarbutton id="${each.itemno}" label="${each.itemno}" forEach="${item}"
style="font:30px/1.2em Arial, Verdana, sans-serif;" onClick="myMethod(self)"/>

In Java code,

public void myMethod(Toolbarbutton btn){
System.out.println(btn.getId());
}

/Jumper

link publish delete flag offensive edit

answered 2007-09-03 13:08:46 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4498243

By: jumperchen

Hi Andy,

The Executions.getCurrent().setAttribute() is the same with request.setAttribute(), so you can use the Executions.getCurrent().getAttribute() or request.getAttribute().

/Jumper

link publish delete flag offensive edit

answered 2007-09-03 15:18:25 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4498203

By: andy-susanto

hai Jumper,

how other.zul get value of "key1" ?


TIA,

andy susanto

link publish delete flag offensive edit

answered 2007-09-03 16:42:57 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4498515

By: andy-susanto

hai Chen,

zul file

<?init class="ibs.mainapp" arg0="key1" ?> <label value="${key1}"/>

i am sorry i try create a java code like this

public class mainapp implements Initiator,Controller{

public void doInit(Page page,Object[] args){
String key1 = request.getAttribute();
}

public void doAfterCompose(Page page) throws Exception{}

public void doCatch(Throwable throwable){}

public void doFinally(){}

}

the problem is request method can not be resolved. Could you give me another an example ?



TIA,

andy susanto




link publish delete flag offensive edit

answered 2007-09-03 23:44:11 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4498944

By: rudi_black

hi andy,

i'm not sure if i'm i'm right but u r using implements instead of extends for your class. to my knowledge, implements is used for interfaces while extends is for class (again i may be wrong).
in my macro components (java class) ... i always extends the basic class and i got no problem what so ever w/ the methods, properties etc...


good luck
-rudi-


link publish delete flag offensive edit

answered 2007-09-04 01:02:01 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4499004

By: jumperchen

Hi Andy,

You mistook my meaning.
Try this,

In other1.zul file,

<zscript>
Executions.getCurrent().setAttribute("key1", "val1"); Executions.getCurrent().forward("/other2.zul");
</zscript>

In other2.zul file,
<zscript>
Executions.getCurrent().getAttribute("key");
</zscript>

Please take a look at the API -
http://www.zkoss.org/javadoc/2.4.1/zk/org/zkoss/zk/ui/Execution.html#getAttribut
e(java.lang.String)

/Jumper

link publish delete flag offensive edit

answered 2007-09-06 16:42:49 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4504635

By: andy-susanto

Hai Chen,

i read a javadoc but i cannot find about how to pass a variable between zul file.

this is my a zul and java file that will call another zul file when toolbarbutton click

first.zul
<?init class="ibs.transaksi.spa.locker.Locker" arg0="locker" ?> <toolbarbutton id="${each.lockerNo}" onClick="new ibs.transaksi.spa.locker.Locker().test(self)"
label="${each.lockerNo}" forEach="${locker}"
style="font:30px/1.2em Arial, Verdana, sans-serif;"/>


package ibs.transaksi.spa.locker;

import html.tag.NewLine;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.util.Initiator;
import org.zkoss.zul.Toolbarbutton;

import database.AutoReconnect;

public class Locker extends LockerObj implements Initiator{

public void doInit(Page page,Object[] args){
List tabLabel = new LinkedList();

Connection Con = null;
PreparedStatement pstmtListTransLocker = null;
try{
Con = AutoReconnect.getConection();

StringBuffer sbSQLStatement = new StringBuffer("SELECT LOCKER_NO,LOCKER_ID ");
sbSQLStatement.append("FROM LOCKER ");
sbSQLStatement.append("WHERE LOCKER_TYPE = 'M' AND LOCKER_SUSPEND=0 ");
sbSQLStatement.append("ORDER BY LOCKER_NO ");

pstmtListTransLocker = Con.prepareStatement(sbSQLStatement.toString());
ResultSet rs = pstmtListTransLocker.executeQuery();

while (rs.next()){
tabLabel.add(new
LockerObj(rs.getString("LOCKER_ID"),rs.getString("LOCKER_NO")));
}


}
catch(SQLException error){
System.err.print("Open Connection Gagal ".concat(error.getMessage()).concat(NewLine.CodeBreak()));
}finally{
page.setVariable((String) args[0], tabLabel);

//Close Connection
if (Con != null){
try{
Con.close();
Con = null;
}
catch(SQLException error){
System.err.print("Close Connection Gagal ".concat(error.getMessage()).concat(NewLine.CodeBreak()));
}
}
}


}

public void doCatch(Throwable ex){

}

public void doFinally(){

}

public void doAfterCompose(Page arg0) throws Exception {
// TODO Auto-generated method stub

}

public void test(Toolbarbutton a){
StringBuffer sbUrl= new StringBuffer("/forms/display/test.zul");
Executions.getCurrent().setAttribute("key", a.getId());
Executions.sendRedirect(sbUrl.toString());
}
}


second.zul( this file show an attribute which user click from first.zul) <?init class="ibs.mainapp" arg0="rt" ?> <label value="${rt}"/>

package ibs;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.util.Initiator;

public class mainapp implements Initiator,Controller {

public void doInit(Page page,Object[] args){
String test = page.getAttributes().toString();
System.out.println(page.getVariable("key"));

page.setVariable((String) args[0], test);
}

public void doAfterCompose(Page page) throws Exception{}

public void doCatch(Throwable throwable){}

public void doFinally(){}

public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse
res)
throws ServletException,IOException{

return new ModelAndView("/forms/display/display.zul");
}
}


Chen can you help me how can i achieve my goal ?


TIA,

andy susanto


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: 2007-09-02 04:28:59 +0800

Seen: 1,921 times

Last updated: Apr 10 '09

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