0

Proper Destruction??

asked 2009-12-14 04:30:07 +0800

nevyn gravatar image nevyn
159 2

Hi,

Another 'lil problem.

I've got the following code:
Java:

import org.zkoss.zk.ui.util.GenericForwardComposer;
//import org.zkoss.zkex.zul.Fisheye;
import org.zkoss.zkex.zul.Fisheyebar;
import org.zkoss.zul.Include;
import org.zkoss.zul.Label;
import org.zkoss.zul.Tab;
import org.zkoss.zul.Tabbox;
import org.zkoss.zul.Tabpanel;
import org.zkoss.zul.Tabpanels;
import org.zkoss.zul.Tabs;
import org.zkoss.zul.Window;

public class febTest extends GenericForwardComposer {
	
	//static private Fisheyebar febMenu;	//autowired --Will be used to add fisheye objects to 
	static private Label lblStatus;			//autowired --Temporary for testing purposes
	//static private Tabbox tbxMain;		//autowired --Needed to access tabs and tabpanels
	static private Tabs tbsMain;			//autowired --Used for adding tabs
	static private Tabpanels tbpsMain;		//autowired --Used for adding tabpanels
	
	public void onItemClicked(){
		Tab tbNew=new Tab();
		Tabpanel tbpNew=new Tabpanel();
		Window winTest=new Window();
		
		
		tbNew.setLabel("It Works!");
		tbNew.setClosable(true);
		tbNew.setParent(tbsMain);
		
		Include test=new Include();
		
		test.setSrc("/test.zul");
		winTest.setHeight("100%");
		winTest.appendChild(test);
		tbpNew.appendChild(winTest);
		tbpNew.setParent(tbpsMain);
		
		lblStatus.setValue("something's happened");
	}
}

And the zul file:

<window id="main" apply="febTest" height="100%">
	<borderlayout height="100%"  >
		<north>
			<label id="lblStatus" value="unchanged" />
		</north>
		<center>
			<tabbox orient="vertical" width="100%" height="100%" id="tbxMain">
				<tabs id="tbsMain" width="200px" />
				<tabpanels id="tbpsMain" />
			</tabbox>
		</center>
		<south title="Menu" collapsible="true" flex="true">
			<window id="menu" height="80px" apply="febTest">
				<div align="center">
					<fisheyebar id="febMenu" attachEdge="center" itemMaxHeight="80" itemMaxWidth="80"  style="position: relative; margin-top: 30px" labelEdge="top">
						<fisheye id="feiTest" label="test" image="/images/background.png" forward="onClick=onItemClicked" />
					</fisheyebar>
				</div>
			</window>
		</south>
	</borderlayout>
</window>

I'm using tomcat on Ubuntu. As you can see, it's all in a state of testing and trying to figure out what I'm doing (thus the bad variable names and the like). Anyway, whenever I refresh the page, and then try to click on the item in the fisheyemenu, I get the following error:

Access denied: component, <Tabs tbsMain>, belongs to another desktop: [Desktop g05]

I'm lead to believe that I can leave garbage collection to Java. I did find this passage in the Apress ZK Ajax without the Javascript book:

"...once a component is detached from a page, it is no longer managed by ZK if the application does not keep any reference to it. The memory occupied by the component will be released by the Java Virtual Machine (JVM) garbage collector. However, if the application holds a reference to the component, it will not be collected with the garbage..."

So do I need to somehow remove the reference to the component in the Java file?

Thanks for any help you're able to offer.

Regards,
Nevyn.

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2009-12-14 04:33:03 +0800

nevyn gravatar image nevyn
159 2

Oh - I forgot to add: I can see the page if I reload the app (in tomcat) but if I do a reload on the page again (in the browser), it comes up with the error again.

link publish delete flag offensive edit

answered 2009-12-15 04:13:41 +0800

nevyn gravatar image nevyn
159 2

*bump*

Has anyone come across this or a similar problem before? I'm I doing something obviously wrong?!?

link publish delete flag offensive edit

answered 2009-12-15 04:18:32 +0800

nevyn gravatar image nevyn
159 2

Hey - Just figured this one out. So for anyone having the same problem:
Static variables are not your friend...

link publish delete flag offensive edit

answered 2009-12-15 04:23:36 +0800

tmillsclare gravatar image tmillsclare
799 2 5 30

updated 2009-12-15 04:46:54 +0800

@nevyn

There is another problem relating to your onClick event, this is not how you setup ZK using the MVC pattern.

Please take a look at this MVC tutorial!

Note that it is highly recommended to put your Java class into a package, maybe "test.febTest" and then specify the name in the Window's apply attribute apply="test.febTest"

Also note that the java function should read:

EVENT_NAME$CONTROL NAME(Event e)

therefore in your case the skeleton of the function should be

public void onClick$feiTest{
    ....		
}

See if that gets you started!

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: 2009-12-14 04:30:07 +0800

Seen: 1,053 times

Last updated: Dec 15 '09

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