Sessionless removes the need to store form data in sessions by allowing pages to get rendered directly on unsuccessful form submissions. The redirect is maintained in all other (successful) posts. This means that form fields and error messages don't need to be persisted and a sessionless app can easily be built.
It works by decorating the RequestExceptionHandler with an implementation which catches PageValidationExceptions and renders a page directly. If no PageValidationException gets thrown then app will behave in the same way as a standard Tapestry application.
To use sessionless simply add the norobot repository to your pom
<repository>
<id>tapestry</id>
<url>http://norobot.googlecode.com/svn/maven2</url>
</repository>
Then add the dependency
<dependency>
<groupId>org.norobot</groupId>
<artifactId>sessionless</artifactId>
<version>1.0</version>
</dependency>
Then simply throw a PageValidationException in your submit method to get the page rendered without a redirect.
void onSubmitFromLogin() throws PageValidationException {
if (hasFormErrors()) {
throw new PageValidationException(this);
}
}
If the form has errors then the page gets rendered with no redirect.
No comments:
Post a Comment