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

/Jumper

james
255 2

"Instead, you have to use getZScriptVariable to retrieve variables defined in zscript. Similarly, you can use getZScriptClass to retrieve classes and getZScriptMethod to retrieve methods defined in zscript. "
But when i put the "getZScriptMethod" in my java file, it doesn't work.

The onClick EventListener...

public void onEvent(Event event) throws Exception {
page.getZScriptMethod("MasterPrepareForm()");
}

I'm using eclipse, and for some reason, it doesn't even recognize "page".
The error message that eclipse diplays is, "page cannot be resolved".
Still, I exported to .war file, and loaded it on the server. I get an error when trying to access the zul file that uses the zscript and rowRenderer.java file.
in the grid section it says this:
Unresolved compilation problem:
page cannot be resolved

Thanks for the guide Jumper... but there must be something else because that isn't working.
It seems like that is meant for being within the same file, or perhaps even using doing 'use="javaClass"' or something like that. But for live data and using a rowRenderer, it isn't working.

Anyone else have any ideas?
Or perhaps if I implemented it incorrectly? (didn't seem too complicated)

james
255 2

Does anyone have any ideas on what I could do with this? ....Being able to call a zscript function contained on page, from a rowRenderer?

Excerpt from zul file

//(in zscript tags)
ListModel orderEntryListModel = new SimpleListModel(orderEntryList.toArray());
viewGrid.setModel(orderEntryListModel);
viewGrid.setRowRenderer(new view.EntryRowRenderer());

Excerpt from rowRender.java file
TBB.addEventListener("onClick", new EventListener() {
public void onEvent(Event event) throws Exception {
page.getZScriptMethod("MasterPrepareForm()");
}
});
...But "page" isn't even recognized (as noted in my previous comment)

Is there anyone who's had any experience with this (anyone really) who can help me out?
Any and all help is appreciated. Thank you for your time.
-James

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

Hi,

In Java code, you have to receive the page via a component or another method, for example,

TBB.getPage();
or
event.getTarget().getPage();


/Jumper

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?

james
255 2

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

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

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

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

/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

[hide preview]