0

call zscript function from rowRenderer.java?

asked 2009-04-27 16:56:02 +0800

james gravatar image james
255 2

I am loading on demand and using a rowRenderer.java file to format the information.
I want to add an onClick function that will call a zscript function on my page.
I can easily add an onClick to call a zscript function when I hard code it in the zul file,
but when i try and just call the zscript function, this is the error that i get.
"The method MasterPrepareForm() is undefined for the type new EventListener(){}"

Does anyone have experience with this, or know how I might be able to do it?
Thanks to all who can help.
-James

delete flag offensive retag edit

14 Replies

Sort by ยป oldest newest

answered 2011-09-19 21:04:18 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

You may use this component (soundmanager) instead.

link publish delete flag offensive edit

answered 2011-09-15 03:24:00 +0800

shrunker gravatar image shrunker
3

I want to play sound notification using zscript.
Any ideas to do it??Thx b4

link publish delete flag offensive edit

answered 2009-05-15 16:21:21 +0800

james gravatar image james
255 2

Ya... I could do that, but then I'm not sure how I would associate the files properly.
So I have the EntryRowRenderer.java file creating the component and adding the onClick event.
Now I have OrderScript.java containing the converted zscript.
I put them in the same package (orders).
How do I call the function properly?
How would I call the TESTFUNC() in orders.OrderScript from the orders.EntryRowRenderer class?

Thanks for the advice Jumper, I hope this will work right.
-James

link publish delete flag offensive edit

answered 2009-05-15 06:18:45 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi,

Why not move the function into a Java class? (high performance)

/Jumper

link publish delete flag offensive edit

answered 2009-05-15 04:36:35 +0800

james gravatar image james
255 2

To use "self.getNamespace()", I get this error:

 Unresolved compilation problem: 
	self cannot be resolved

So I tried this...
event.getTarget().getPage().getZScriptFunction(event.getTarget().getPage().getNamespace(), "TESTFUNC", null);

note: TESTFUNC() just does a simple alert box.
this ended up not doing anything, just like not having 3 arguments and only the 2 (see the example in my previous post)...

I've tried this using combinations of "TBB.getPage()", "event.getPage()", and "event.getTarget().getPage()" to try and have the getZScriptFunction() function pull from the right page/place.
note: "TBB" is in reference to the toolbarbutton. ie:"final Toolbarbutton TBB = new Toolbarbutton();"

All of which have ended in failure. These also produce no error message. I click on the toolbarbutton and nothing happens. (the status bar notes that there is some javascript when you hover the mouse of the button though)

Thank you though Jumper. Unfortunately, it's not working. Do you have any other ideas that I might be able to try?

-James

link publish delete flag offensive edit

answered 2009-05-15 02:05:00 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Have you tried to call the three arguments of the getZScriptFunction(), like - getZScriptFunction(self.getNamespace(), "sayHi", null);

/Jumper

link publish delete flag offensive edit

answered 2009-05-14 14:45:14 +0800

james gravatar image james
255 2

updated 2009-05-14 14:47:32 +0800

Jumper thank you for your reply.
The problem is this though,
I'm creating a <toolbarbutton /> with an onClick event from a java file, not in a zul file.
within the zul file everything works well.
But I can't figure out how to programatically (within the java file) create an onClick event that will call a function that is writen in zscript in the zul file.
Example:
EntryRowRenderer.java

public class EntryRowRenderer implements RowRenderer{ 
    public void render(Row row, java.lang.Object data) throws Exception {
	final ViewOrders order = (ViewOrders) data;
	final Toolbarbutton TBB = new Toolbarbutton();
	TBB.setLabel(order.get_prod());
	TBB.addEventListener("onClick", new EventListener() {
	    public void onEvent(Event event) throws Exception {
	        TBB.getPage().getZScriptFunction("EditAndPrepare("+order.get_orderID()+")", null); // this is the line in question.
	    }
	});
	TBB.setParent(row);
	...
    }
}

entry.zul

<zscript>
...	
void EditAndPrepare(String newWebOrderID){
    SetEntryEdit(newWebOrderID);
    MasterPrepareForm();
}
...
</zscript>

<grid id="viewGrid" mold="paging" pageSize="20" pagingPosition="both">
    <columns menupopup="auto" sizable="true">
	<column label="Product" width="120" />
	<column label="Procedure" width="130" />
	<column label="DT" width="50px" />
	<column label="Cal Date" width="80px" />
	<column label="CT" width="50px" />
	<column label="Amount" width="58px" />
	<column label="Unit" width="40px" />
	<column label="Qty" width="30px" />
	<column label="Patient" width="110" />
	<column label="Note" width="90" />
    </columns>
</grid>
<zscript>
    ArrayList orderEntryList = main.viewOrdersCombine(main.getDelDate());
    ListModel orderEntryListModel = new SimpleListModel(orderEntryList.toArray());
    viewGrid.setModel(orderEntryListModel); 
    viewGrid.setRowRenderer(new view.EntryRowRenderer());
</zscript>

So I want the button created in EntryRowRenderer.java to execute the function EditAndPrepare() in entry.zul.
Note: the toolbarbutton will be placed in the grid (viewGrid) when the setRowRenderer() is called
I have also tried this function (which also fails to get the right function when you click on the toolbarbutton).

event.getTarget().getPage().getZScriptFunction("EditAndPrepare("+order.get_orderID()+")", null);

I hope this all makes sense as to what I'm asking for...
(in a separate java file, create a component and add an onClick event that will call/execute a function written in zscript in a zul file)

Thanks to everyone who has taken time to help me.
-James

link publish delete flag offensive edit

answered 2009-05-14 01:53:48 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi James,

The following code works for me.

<zk>
<zscript>
void sayHi() {
alert("Hi");
}
</zscript>
<button label="test">
<attribute name="onClick">
org.zkoss.xel.Function fn = page.getZScriptFunction(self.getNamespace(), "sayHi", null);
fn.invoke(null, null);
</attribute>
</button>
</zk>

/Jumper

link publish delete flag offensive edit

answered 2009-05-13 13:35:46 +0800

james gravatar image james
255 2

Anyone have any ideas on this? I still haven't been able to figure it out.

Thanks
-James

link publish delete flag offensive edit

answered 2009-04-30 15:44:24 +0800

james gravatar image james
255 2

Jumper, thanks. That works to get the page.
So these are the new problems i have about this... (sheesh, can't it be a little easier?)
getZScriptMethod() doesn't work. I can use getZScriptClass() or getZScriptFunction()
So I put

TBB.getPage().getZScriptFunction("MasterPrepareForm()", null)

note: getZScriptFunction(String, Class[]) I'm not sure what to put for "Class[]" so i just put null.
But it ends up not even calling/executing the function.
I added a message box to the function, and that doesn't even come up or anything...

Thanks for your help so far. Please continue to help.
Anyone have any ideas of why it isn't calling it? is the "class[]" argument necessary? and if so what would i need to put there just to call the function?

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: 2009-04-27 16:56:02 +0800

Seen: 1,351 times

Last updated: Sep 19 '11

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