Created
May 16, 2011 12:23
-
-
Save karussell/974349 to your computer and use it in GitHub Desktop.
wicket: submitting a form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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