0

Can't access url parameter from the Include component

asked 2011-08-23 13:02:02 +0800

gyowanny gravatar image gyowanny
283 1 2 6

updated 2011-08-23 13:10:25 +0800

Hi guys,

I have this ZUL file which is loaded as an Include component:

<?page contentType="text/html;charset=UTF-8"?>
<zk>
	<panel id="portletVideo" apply="com.test.zk.portlets.PortletVideoCtrl"/>
</zk>

I include the file above into a given window by using the following URI:

/portlet_video.zul?prod=10

Unfortunately I can't find the parameter "prod" by calling execution.getParameter("prod") in the com.test.zk.portlets.PortletVideoCtrl class, it's returning null and I've already listed the Parameters Map but it's not there.
Am I doing that in the right way like applying the controller class right in the panel component? What is the best way to get the parameter values in an Included zul file?

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-08-24 11:00:32 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

Hi gyowanny,

The following sample should work.

The main zul:

<?page title="URL Parameters Test" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="URL Parameters Test" border="normal">

	<include src="/urlparameters/header.zul" />

</window>
</zk>

The include page:

<?page contentType="text/html;charset=UTF-8"?>
<zk>
<window border="none" width="100%" height="100%" apply="urlparameters.Header">

	<label id="lblHeader" />
	
</window>
</zk>

And the composer of the header.zul:

package urlparameters;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.api.Label;

public class Header extends GenericForwardComposer {

	private static final long serialVersionUID = 1L;
	
	Label lblHeader;
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		
		try {
			super.doAfterCompose(comp);
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		
		/*
		 * retrieve url parameters
		 */
		String[] parameter = (String[]) param.get("parameter");
		
		if (parameter != null)
			lblHeader.setValue( "Congratulations! Your parameters value is " + parameter[0] );
		else
			lblHeader.setValue( "No parameters found. URL should be something like http://yourserver/yoursite/main.zul?parameter=param-value" );
	}

}

Hope that helps
/Costas

link publish delete flag offensive edit

answered 2011-08-24 11:38:22 +0800

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

updated 2011-08-24 11:38:46 +0800

Good job , Costas!

Here's a runnable sample for it which based on Costas's code .

ZKFiddle-Link

HeaderComposer.java
package jbl6i4e$v1;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;

public class HeaderComposer extends GenericForwardComposer{


Label lblHeader;

@Override
public void doAfterCompose(Component comp) throws Exception {

try {
super.doAfterCompose(comp);
}
catch (Exception e) {
e.printStackTrace();
}

/*
* retrieve url parameters
*/
String[] parameter = (String[]) param.get("test");

if (parameter != null)
lblHeader.setValue( "Congratulations! Your parameters value is " + parameter[0] );
else
lblHeader.setValue( "No parameters found. URL should be something like http://yourserver/yoursite/main.zul?parameter=param-value" );
}
}


header.zul
<?page contentType="text/html;charset=UTF-8"?>
<zk>
<window border="none" width="100%" height="100%" apply="jbl6i4e$v1.HeaderComposer">

<label id="lblHeader" />

<div>
Load from EL [ <label value="${param.test}" />]
</div>
</window>
</zk>


index.zul
<?page title="URL Parameters Test" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="URL Parameters Test" border="normal">

<include src="header.zul?test=5" />

</window>
</zk>

link publish delete flag offensive edit

answered 2011-08-25 14:11:14 +0800

gyowanny gravatar image gyowanny
283 1 2 6

Great guys!

That worked fine! Thanks a bunch.

Gyo

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-08-23 13:02:02 +0800

Seen: 832 times

Last updated: Aug 25 '11

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