How to call this js function from java

asked 2021-09-27 23:55:18 +0800

softteam gravatar image softteam
120 8

updated 2021-10-13 10:42:31 +0800

cor3000 gravatar image cor3000
6168 2 7
ZK Team


I got a function in a zul file that opens a grid menupop in the target location insted of the column location:

image description

My zul file has:

    <zk xmlns:w="client" xmlns:n="native">
                function openColPopupHere(event, wgt, target){

   <a iconSclass="z-icon-ellipsis-v z-icon-lg" 
   <grid id="GRIDCenso" sclass="GRIDCenso" mold="paging" pageSize="10" 
    pagingPosition="bottom" span="6" sizedByContent="true"  width="100%" 
    xmlns:a="client/attribute" a:data-scrollable="true" 
     <columns menupopup="auto" sizable="true" 

Now, I got a new grid with no ids so I cannot pass the third parameter and I tried to do this in java. This grid is like this:

image description

In my zul file:

<a iconSclass="z-icon-ellipsis-v z-icon-lg" 
   onClick="@command('configurarVista', event=event, target=event.getTarget())"/>

In my java file:

        public void configurarVista(@BindingParam("target")A  boton, 
         @BindingParam("event")Event  event) {
          Column col = (Column) 

But this is not working at all. The function is called, but nothing happens. How can I achieve this in java? I can use a new js function, there is no problem.

Thank you,


delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-10-13 11:23:33 +0800

cor3000 gravatar image cor3000
6168 2 7
ZK Team

updated 2021-10-13 11:24:21 +0800

I'd avoid hard coding such a long chain of nested parent child relations in a viewmodel ... the goal is to be independent of the view. Instead if needed I'd suggest to simply locate the column widget at client side directly - without the server side round trip.

In this example: https://zkfiddle.org/sample/2ukdoe6/1-open-column-popup-from-button

I added a button demonstrating how to use jquery to locate the first grid column, and convert it back into the corresponding zk JS widget object (jq()...zk.$();)

<button w:onClick="openColPopupHere(event, this, jq(this.parent).find('@grid @column').zk.$());"/>

If you really need to call a method from server side, you can't just concatenate strings and hope for the best, this will simply call toString() on the server side objects, which doesn't make sense to the JS engine. Instead you have to get rid of the event object that doesn't translate into JS anyway (e.g. just mock it) and pass the button and column component into an AuInvoke object along with the function name. AuInvoke will map the server side component object to the client side widget. Clients.response() can take the AuInvoke object and execute it at client side. Basically any ZK UI update goes more or less through Clients.response() just using a different type of response class.

Here an updated example. https://zkfiddle.org/sample/2ukdoe6/2-open-column-popup-from-button

As you'll notice the popup position jumps when opened first, which would need additional care.

So in the end I prefer the pure JS variant. I'd only go through the server if there's a specific requirement that can only be achieved in Java code.

link publish delete flag offensive edit
Your answer
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

1 follower



Asked: 2021-09-27 23:55:18 +0800

Seen: 5 times

Last updated: Oct 13

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