Skip to content

@karussell /HomePage.html
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
wicket: submitting a form
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >
<head>
<title>Wicket Quickstart Archetype Homepage</title>
</head>
<body>
<form wicket:id="searchform">
<input type="text" wicket:id="textField" name="query"/>
<input type="submit" value="Search"/>
</form>
</body>
</html>
package com.mycompany;
import java.io.Serializable;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.apache.wicket.protocol.http.WebRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Homepage
*/
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
private Logger logger = LoggerFactory.getLogger(getClass());
public HomePage(final PageParameters parameters) {
super(parameters);
String q = parameters.getString("q");
final Model txtModel = new Model(q) {
@Override
public Serializable getObject() {
if (super.getObject() == null)
return "";
else
return super.getObject();
}
};
TextField text = new TextField("textField", txtModel);
Form form = new Form("searchform") {
@Override
protected void onSubmit() {
logger.info(getMethod() + ": onSubmit textField object:" + txtModel.getObject());
PageParameters pp = new PageParameters();
pp.add("q", txtModel.getObject().toString());
setResponsePage(HomePage.class, pp);
}
};
add(form);
form.add(text);
logger.info(getMethod() + ": HomePage ctor params: " + parameters);
}
public String getMethod() {
return ((WebRequest) getRequest()).getHttpServletRequest().getMethod();
}
}
package com.mycompany;
import org.apache.wicket.protocol.http.WebApplication;
/**
* Application object for your web application. If you want to run this application without deploying, run the Start class.
*
* @see com.mycompany.Start#main(String[])
*/
public class WicketApplication extends WebApplication {
/**
* Constructor
*/
public WicketApplication() {
}
/**
* @see org.apache.wicket.Application#getHomePage()
*/
public Class<HomePage> getHomePage() {
return HomePage.class;
}
@Override
protected void init() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.