-
Notifications
You must be signed in to change notification settings - Fork 297
JEE Web Integration
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:
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):
<wicket:jsp file="/de/test/jsp/TestPage.jsp"/> or <wicket:servlet path="/de/test/servlet/Servlet/"> or <wicket:jsf file="/TestPage.xhtml"/>
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¶m2=value2"/>">LINK</a> JSF Example: Tag is the same but should not be used within a href, please refer to the EL-Functions
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')}
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();
}
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>
- https://cwiki.apache.org/confluence/display/WICKET/Including+JSP+files+in+HTML+templates
- http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-and-JSP-servlet-wrapping-td4407174.html
- 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>