Skip to content

JEE Web Integration

klopfdreh edited this page Oct 23, 2014 · 5 revisions

wicketstuff-jee-web (previously wicket.jsp)

The JEEWebResolver is used to embed Servlet, JSP abd JSF content into wicked HTML pages, by a custom Wicket-Tag. It is tested with Wicket 6.x / 7.x. Because include is used to apply the content, every restrictions of include is applied to the embed content. (No header modifications and so on). To use it you should registered it to the page settings in the init-Method of the Wicket-Application:

Setup

WebApplication:

@Override
protected void init() {
	super.init();
	getPageSettings().addComponentResolver(new JEEWebResolver());
}

A tag specifies the location which embed content to load. (The argument is given to the getRequestDispatcher method of the ServletContext):

Usage

<wicket:jsp file="/de/test/jsp/TestPage.jsp"/>

or 

<wicket:servlet path="/de/test/servlet/Servlet/">

or

<wicket:jsf file="/TestPage.xhtml"/>

Tags for JSP / JSF

JSP: <%@ taglib prefix="wicket" uri="http://wicketstuff-jee-web.org/functions/jsp" %>
JSF: <div xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:wicket="http://wicketstuff-jee-web.org/functions/jsf">

Tag: url // Parameters: page(required), query(optional) // Example:
JSP Example: <a href="<wicket:url page="mypage.MyTestPage" query="param1=value1&param2=value2"/>">LINK</a>
JSF Example: Tag is the same but should not be used within a href, please refer to the EL-Functions

EL-Functions for JSP / JSF

JSP: <%@ taglib prefix="wicket" uri="http://wicketstuff-jee-web.org/functions/jsp" %>
JSF: <div xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:wicket="http://wicketstuff-jee-web.org/functions/jsf">

EL-Function:
${wicket:url('mypackage.MyPage')}
${wicket:urlWithQuery('mypackage.MyPage','param1=value1')}

Forms (GET / POST)

POST: JSP-Fragment:

<form action="<wicket:url page="mypackage.MyPage2"/>" method="POST">
	<input type="hidden" name="hiddenparam" value="testvalue">
	<input type="submit" value="Submit">
</form>

mypackage.TestPage2:

public TestPage2(PageParameters parameters){
	String hiddenparam = RequestCycle.get().getRequest()
	.getPostParameters().getParameterValue("hiddenparam");
}

GET: JSP-Fragment:

<form action="<wicket:url page="mypackage.MyPage2"/>" method="GET">
	<input type="hidden" name="hiddenparam" value="testvalue">
	<input type="submit" value="Submit">
</form>

mypackage.TestPage2:

public TestPage2(PageParameters parameters){
	String hiddenparam = parameters.get("hiddenparam").toString();
}

Ajax-Support

WebApplication:

    @Override
    protected void init() {
	super.init();
		getPageSettings().addComponentResolver(new JEEWebResolver());
		JEEWebGlobalAjaxHandler.configure(this);
    }

WebPage (IMPORTANT: In constructor use setStatelessHint(false); !!!):

    @Override
    public void onEvent(IEvent<?> event) {
		JEEWebGlobalAjaxEvent castedEvent = 
		JEEWebGlobalAjaxEvent.getCastedEvent(event);
		if (castedEvent!= null) {
			AjaxRequestTarget ajaxRequestTarget = castedEvent.getAjaxRequestTarget();
			
			// Get-Request
			castedEvent.getPageParameters().get("param");
			
			// Post-Request
			castedEvent.getPostParameters().getParameterValue("param")
		}
    }

In JSP:

<a href="#" onClick="${wicket:ajaxGetWithQuery('param=value')}">Update</a>
<a href="#" onClick="${wicket:ajaxGet()}">Update</a>

In JSP with Javascript:

<script type="text/javascript">
	function processCallBack(){
		var url = '${wicket:ajaxCallbackUrl()}';
		var urlWithPreRenderedArgs = 
		'${wicket:ajaxCallbackUrlWithQuery("param=value")}';
		
		// Get-Request
		var url = Wicket.Ajax.applyGetParameters(url,{"param":"value"})
		Wicket.Ajax.wrapget(url);
		
		// Post-Request
		Wicket.Ajax.wrappost(url,{"param":"value"});
	}
	processCallBack();
</script>

Forms (GET / POST given as String to the EL function)

<form onsubmit="${wicket:ajaxFormSubmit('POST')}"> .... </form>

Links

IMPORTANT

  • Will be available in Version 6.18.0 / 7.0.0-M4
  • Dependency:
<dependency>
	<groupId>org.wicketstuff</groupId>
	<artifactId>wicketstuff-jee-web</artifactId>
	<version>/version/</version>
</dependency>
Clone this wiki locally