0

get RealPath of zulfile

asked 2011-05-04 22:29:46 +0800

nilsonhp gravatar image nilsonhp
123 3

Hi, everyone.

I'm having an error with the path of my zul file. This is my code:

package com.siger.main.control.zk;

import org.zkoss.zk.ui.ComponentNotFoundException;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zul.Center;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Tab;
import org.zkoss.zul.Tabpanel;
import org.zkoss.zul.Tabpanels;
import org.zkoss.zul.Tabs;
import org.zkoss.zul.Window;

public class PessoaTabController extends Window implements AfterCompose,
		TabController {

	public void afterCompose() {
		Components.wireVariables(this, this);
		Components.addForwards(this, this);
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Center pessoa_center;
	
	public void onCreate$pessoa_window() throws InterruptedException {
		showPage("/view/atores/tabs/pessoa/cards/pessoaCard.zul", "pessoaCard");
	}

	public void onClick$btn1(Event event) throws InterruptedException {
		showPage("/view/atores/tabs/pessoa/cards/pessoaCard.zul", "pessoaCard");
	}

	public void showPage(String zulFilePathName, String tabName)
			throws InterruptedException {

		try {

			// get the tabs component
			Tabs tabs = (Tabs) pessoa_center.getFellow("pessoa_div").getFellow(
					"pessoa_tabbox").getFellow("pessoa_tabs");

			/**
			 * Check if the tab is already opened than select them and<br>
			 * get out of here. If not than create them.<br>
			 */

			Tab checkTab = null;
			try {

				checkTab = (Tab) tabs.getFellow("tab_" + tabName.trim());
				checkTab.setSelected(true);

			} catch (ComponentNotFoundException ex) {
				// Ignore if can not get tab.
			}

			if (checkTab == null) {

				Tab tab = new Tab();
				tab.setId("tab_" + tabName.trim());
				tab.setLabel(tabName.trim());
				tab.setClosable(true);

				tab.setParent(tabs);
				Tabpanels tabpanels = (Tabpanels) pessoa_center.getFellow(
						"pessoa_div").getFellow("pessoa_tabbox").getFellow(
						"pessoa_tabs").getFellow("pessoa_tabpanels");
				Tabpanel tabpanel = new Tabpanel();
				tabpanel.setHeight("100%");
				tabpanel.setStyle("padding: 0px;");
				tabpanel.setParent(tabpanels);

				/**
				 * create the page and put it in the tabs area
				 */
				Executions.createComponents(zulFilePathName, tabpanel, null);

				tab.setSelected(true);
				tab.setVisible(false);
			}

		} catch (Exception e) {

			Messagebox.show(e.toString());
		}
	}

}

My problem is: although my zulFilePathName is correct, when it tries to run, returns a nullpointerException. I use similar code in other files and it work perfectly. Does anyone now how can i get the real path of my pessoa card, and pass it in my method showPAge() ?? thanks a lot.

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2011-05-04 23:09:26 +0800

wrt2k4 gravatar image wrt2k4
24

Hi,

Try this:

ServletContext sc = (ServletContext)Sessions.getCurrent().getWebApp().getNativeContext();
sc.getRealPath("view/atores/tabs/pessoa/cards/pessoaCard.zul");

link publish delete flag offensive edit

answered 2011-05-04 23:41:01 +0800

nilsonhp gravatar image nilsonhp
123 3

Hi, wrt2k4, thanks.

i tried your solution, and he returns the following Exception:

org.zkoss.zk.ui.UiException: Page not found: /view/D:\Workspace\siger\view\atores\tabs\pessoa\cards\pessoaCard.zul

but the path D:\Workspace\siger\view\atores\tabs\pessoa\cards\pessoaCard.zul is the location im my HD.

Any suggestion?

thanks

link publish delete flag offensive edit

answered 2011-05-05 02:30:10 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

You'll need to use absolute paths:

sc.getRealPath("/view/atores/tabs/pessoa/cards/pessoaCard.zul");

Cheers, Maik

link publish delete flag offensive edit

answered 2011-05-05 09:17:01 +0800

nilsonhp gravatar image nilsonhp
123 3

i sent the absolute path

sc.getRealPath("/view/atores/tabs/pessoa/cards/pessoaCard.zul");

and then I had the above error.

link publish delete flag offensive edit

answered 2011-05-05 09:33:06 +0800

huubf gravatar image huubf
69 1

just use it for the context path, since you know the rest allready

session.getWebApp().getNativeContext().getRealPath("/");
Huub

link publish delete flag offensive edit

answered 2011-05-05 10:00:38 +0800

nilsonhp gravatar image nilsonhp
123 3

Still not work. returns a null pointer Exception

link publish delete flag offensive edit

answered 2011-05-05 14:49:13 +0800

nilsonhp gravatar image nilsonhp
123 3

Solved, the problem was in the executions. i just refactored somo folder and the solution give by wrt2k4 did the job. thanks for the help.

link publish delete flag offensive edit

answered 2015-08-29 17:20:37 +0800

ilovedongri gravatar image ilovedongri
1

Hi nilsonhp, would you please show me how to solve your problem?. Thanks

link publish delete flag offensive edit

answered 2015-08-30 10:23:35 +0800

Darksu gravatar image Darksu
1991 1 4

Hello ilovedongri,

The most possible solution that nilsonhp used was to refactor the folders of his project in order to be accessed correctly.

If you still have the same issue please post your project's directory structure and mention the source->target pages you want to connect.

Best Regards,

Darksu

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: 2011-05-04 22:29:46 +0800

Seen: 496 times

Last updated: Aug 30 '15

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