-
FEATURED COMPONENTS
First time here? Check out the FAQ!
So I have a window id="win1" that is visible=false and contains 1 button "submit".
Outside of win1, I have multiple buttons: "but1", "but2", "but3", etc.
When I click on any one of the buttons but1, but2, but3, win1 is set to visible.
When I click on "submitbut" of win1 want the text of the button (ex but3) to be setLabel="something".
Is there something that can allow me to save the "parent button that set the window to visible?" Maybe some
Button t = Executions.getcurrentbuttonpressed();
or win1.getParentthatsetvisibletotrue();
?
You didn't give many details of your programming model, so start here: event handlers and then maybe to the small talks page and read up on MVC: Small Talks
Yeah, this is assuming its all done on one index.zul with <zscript> tags with no MVC involved.
With my understanding with ZK, you have few possible ways to achieve this.
1) In your onClick handler for but1 (similarly for but2 and but3), save the but1 as an attribute of win1. In your onClick handler for the submit button in win1, you retrieve the calling button from the win1 attribute.
2) You can get the parent of win1, whose space contains your but1, but2, and but3. So you can access those buttons by win1.getParent().getFellow("but1");
3) You can publish an event with the data that your listener can use.
Try this:
<zk> <window id="win" border="normal" style="padding:25px;"> <window id="win1" border="normal" visible="false" style="padding:25px;"> <button label="Submit"> <attribute name="onClick"> self.getParent().getParent().getFellow("btn3").setLabel("Something"); </attribute> </button> </window> <hlayout> <button id="btn1" label="Button 1" onClick="win1.setVisible(true);"/> <button id="btn2" label="Button 2" onClick="win1.setVisible(true);"/> <button id="btn3" label="Button 3" onClick="win1.setVisible(true);"/> </hlayout> </window> </zk>
Yeah, I can see that working, but it would be nice if I could not have to get btn3 at all and just get the button what was clicked to spawn the button:
So instead of:
self.getParent().getParent().getFellow("btn3").setLabel("Something");
I could just do:
self.getParentButtonthatwasClickedtoMakethisWindowVisible();
Or maybe even save the Button clicked (btn1, btn2, etc) into some variable that I can pass to "win", so that "win" knows which button had set it to be visible.
self.getParent().getParent().getFellow(-some variable that contains the button that was clicked-).setLabel("Something");
I think event.getTarget() may helps .
(In zul event handler , there exist a implice object called "event" , it's like the Event paramter in zk event handler .)
It will got the component who fire the event .
Hi Tessla,
Try this. I just modified Todd's code.
<zk> <window id="win" border="normal" style="padding:25px;"> <window id="win1" border="normal" visible="false" style="padding:25px;"> <button label="Submit"> <attribute name="onClick"> Button b = (Button) self.getParent().getAttribute("currBtn"); b.setLabel("Something"); </attribute> </button> </window> <hlayout> <button id="btn1" label="Button 1"> <attribute name="onClick"> <![CDATA[ win1.setVisible(true); win1.setAttribute("currBtn", self); ]]> </attribute> </button> <button id="btn2" label="Button 2"> <attribute name="onClick"> <![CDATA[ win1.setVisible(true); win1.setAttribute("currBtn", self); ]]> </attribute> </button> <button id="btn3" label="Button 3"> <attribute name="onClick"> <![CDATA[ win1.setVisible(true); win1.setAttribute("currBtn", self); ]]> </attribute> </button> </hlayout> </window> </zk>
Asked: 2010-10-25 13:18:55 +0800
Seen: 321 times
Last updated: Oct 25 '10