0

How do I get the button component that was clicked before showing a window?

asked 2010-10-25 13:18:55 +0800

Tessla gravatar image Tessla
330 2

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

?

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2010-10-25 13:36:04 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

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

link publish delete flag offensive edit

answered 2010-10-25 13:37:35 +0800

Tessla gravatar image Tessla
330 2

updated 2010-10-25 13:37:46 +0800

Yeah, this is assuming its all done on one index.zul with <zscript> tags with no MVC involved.

link publish delete flag offensive edit

answered 2010-10-25 13:58:58 +0800

windeyu gravatar image windeyu flag of United States
288 3

updated 2010-10-25 13:59:49 +0800

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.

link publish delete flag offensive edit

answered 2010-10-25 14:01:27 +0800

twiegand gravatar image twiegand
1807 3

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>

link publish delete flag offensive edit

answered 2010-10-25 14:09:00 +0800

Tessla gravatar image Tessla
330 2

updated 2010-10-25 14:09:32 +0800

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

link publish delete flag offensive edit

answered 2010-10-25 21:05:51 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

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 .

link publish delete flag offensive edit

answered 2010-10-25 21:28:14 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

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>

link publish delete flag offensive edit

answered 2010-10-25 23:33:45 +0800

Tessla gravatar image Tessla
330 2

Exactly what I was looking for. Thank you so much!

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: 2010-10-25 13:18:55 +0800

Seen: 321 times

Last updated: Oct 25 '10

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