# call zscript function from rowRenderer.java?

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 retag edit

## 14 Replies

jumperchen
3909 2 8
http://jumperchen.blogspo...

You may use this component (soundmanager) instead.

shrunker
3

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

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

jumperchen
3909 2 8
http://jumperchen.blogspo...

Hi,

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

/Jumper

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

jumperchen
3909 2 8
http://jumperchen.blogspo...

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

/Jumper

james
255 2

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());
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">
<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

jumperchen
3909 2 8
http://jumperchen.blogspo...

Hi James,

The following code works for me.

<zk>
<zscript>
void sayHi() {
}
</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

james
255 2

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

Thanks
-James

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...

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?

[hide preview]