You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alex Zeit <ze...@googlemail.com> on 2010/04/04 10:35:13 UTC
handling Wicket response
Dear All,
How to insert Wicket response into div tag on the page served outside of
Wickets.
This static page looks as follows:
<script type='text/javascript'>
var request;
function doSomeRequest(servletName){
var servlet = servletName; //the name (URI) of your
servlet
var req = servlet; //compiling the request
addrequest(req); //calls the addrequest
function
// request.onreadystatechange = function(){ //this is used to listen for
changes in the request's status
// document.getElementById('test').innerHTML = req.responseText;
// }
if (req.readyState == 4) {
document.getElementById('test').innerHTML = req.responseText;
}
else
alert("loading "+req.statusText);
}
function addrequest(req) {
try { //create a request for
netscape, mozilla, opera, etc.
request = new XMLHttpRequest();
}catch (e) {
try { //create a request for
internet explorer
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e) { //do some error-handling
alert("XMLHttpRequest error: " + e);
}
}
request.open("GET", req, true); //prepare the request
request.send(null); //send it
return request; //return the request
}
</script>
<form name="TestForm" action="">
<input type="button" value="Call wicket page" onclick="doSomeRequest('
http://localhost:8080/?wicket:bookmarkablePage=:wicketqs.Page1&username=John'
)">
</form>
<div id="test">
</div>
Page1.java:
public class Page1 extends WebPage {
public Page1(final PageParameters parameters) {
add(new Label("message1", "User name is
"+parameters.getString("username")));
}
}
Page1.html:
<html xmlns:wicket="
http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >
<head>
<title>Homepage</title>
</head>
<body>
<span wicket:id="message1">message will be here</span>
</body>
</html>
Thank you very much in advance
Alex