ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

How to remove a popup sets by setPopup ?

fabreax
10 Dec 2008 15:38:46 GMT
10 Dec 2008 15:38:46 GMT

Hello,

I add a popup via setPopup, then I want to remove it and add a new popup. Do you know how I can remove the old popup ?

Thank you.

RyanWu
11 Dec 2008 01:11:00 GMT
11 Dec 2008 01:11:00 GMT

you can set new popup directly,
try following code
1. click the user
2. click the button
3. click the user again

<zk>

        <label id="lb" value="user" popup="msg" />
	<popup id="msg" width="300px">
		<vbox>
			This user is online now !
			<toolbarbutton label="Mail him/her"/>
		</vbox>
	</popup>
        <popup id="msg2" width="300px">
		<vbox>
			This user is offline now !
		</vbox>
	</popup>
        <button label="off" onClick="lb.popup=msg2" />
</zk>

fabreax
11 Dec 2008 09:45:50 GMT
11 Dec 2008 09:45:50 GMT

Thank you very much. Your example works well but in Java, I don't have the same behaviour.

This is my code :

Popup popup = new Popup();
popup.appendChild(new Text(Labels.getLabel("editeur.nombredesignes.message") + longueur.toString()));
editeurControleur.appendChild(popup);
mybutton.setPopup(popup);

When I click on mybutton 2 times, I have 2 popups displayed !

RyanWu
12 Dec 2008 09:15:44 GMT
12 Dec 2008 09:15:44 GMT

im not sure what happen in your code,
i use setPopup but i don't have same problem.

<zk>
	<label id="lb" value="user" />
	<popup id="msg" width="300px">
		<vbox>
			This user is online now !
			<toolbarbutton label="Mail him/her" />
		</vbox>
	</popup>
	<popup id="msg2" width="300px">
		<vbox>This user is offline now !</vbox>
	</popup>
	<button label="set 1" onClick="go(1)" />
	<button label="set 2" onClick="go(-1)" />
	<zscript><![CDATA[  //@DECLARATION
	//popup="msg"
	void go(int i) {		
		lb.setPopup(i == 1 ? msg : msg2);	
	}
	]]></zscript>
</zk>

fabreax
12 Dec 2008 10:02:44 GMT
12 Dec 2008 10:02:44 GMT

Thank you.

Is it a ZK bug ?

fabreax
18 Dec 2008 09:38:28 GMT
18 Dec 2008 09:38:28 GMT

Do you know ?

PeterKuo
18 Dec 2008 11:19:36 GMT
18 Dec 2008 11:19:36 GMT

Please provide more code to let us judge if it's a bug or misusage.

No matter what,
Please post it to bug in
http://sourceforge.net/projects/zk1/
to let us track it.

fabreax
18 Dec 2008 15:49:57 GMT
18 Dec 2008 15:49:57 GMT

When I click on a button, it runs this code :

Popup popup = new Popup();
popup.appendChild(new Text("text"));
myWindow.appendChild(popup);
image.setPopup(popup);

When I click on the image, it displays x popups if I clicked x times on the button.

madruga0315Top Contributor
18 Dec 2008 16:54:18 GMT
18 Dec 2008 16:54:18 GMT

this happens because every time you click the button you create a new Popup object with a new Id.

You could set the popup an id, and when the button is clicked, you test if the popup already exists

something like this

Popup popup = (Popup)myWindow.getFellowIfAny("popup");
if(popup == null){
  popup = new Popup();
  popup.setId("popup");
}

// code to manipulated popup (and its children) value

Then you can click the button n times, and only one popup will be showed.

Regards,
/Madruga

fabreax
19 Dec 2008 09:55:17 GMT
19 Dec 2008 09:55:17 GMT

Thank you very much, it works well !