In my example, I actually have an AJAX link that displays the form, and the
resolution from the event handler forwards to form.ftl. So the source page is
form.ftl. But in your example, the source page is index.ftl, so that is being
redisplayed when a validation error occurs. You can easily change this by
having your action bean implement ValidationErrorHandler, and return to form.ftl
upon validation errors:
public Resolution handleValidationErrors(ValidationErrors errors) {
return new ForwardResolution(/WEB-INF/templates/frontend/form.ftl");
}
Hope that helps.
Cheers,
Freddy
http://www.stripesbook.com
-
- Hello, I tried to use Stripes and Query AJAX Forms
- like it is described in http://www.stripesbook.com/blog/index.php?/archives/3-
- Stripes-and-jQuery-AJAX-Forms.html#comments
-
- (very nice article)
-
- It works well in the modern browsers, "Stripes-Success" header approach works
- well too.
-
- But I when error (validation error for example) occurs
-
- This div:
- <div id="form">
- </div>
- is populated not by "form.jsp" content + error messages but by "initial page"
- content + error messages, that produce initial page in initial page effect.
-
- I used FreeMarker, instead of jsp, all files contents is listed below.
-
- I can't understand how to make Initial pages's <div id="form"> to be updated
- with form.jsp contents + error messages and not to put to this div full
- initial page contents with error messages.
-
- Do you have any ideas? Maybe I miss something simple...
-
- @UrlBinding("/")
- public class HomeActionBean extends BaseActionBean {
-
- @DefaultHandler
- @DontValidate
- public Resolution display() {
- return new ForwardResolution("/WEB-INF/templates/frontend/index.ftl");
- }
-
- }
-
- @UrlBinding("/form/{$event}/{firstname}/{lastname}")
- public class FormActionBean extends BaseActionBean {
-
- @Validate(required=true, minlength=5)
- private String firstname;
-
- private String lastname;
-
- @DefaultHandler
- @DontValidate
- public Resolution display() {
- return new ForwardResolution("/WEB-INF/templates/frontend/form.ftl");
- }
-
- public Resolution save() {
- getContext().getResponse().setHeader("AppSuccess", "true");
- return new ForwardResolution("/WEB-INF/templates/frontend/people.ftl");
- }
-
- /* getters/setters */
- }
-
- === Initial Page Template: /WEB-INF/templates/frontend/index.ftl
- [#ftl]
- [#assign s=JspTaglibs["http://stripes.sourceforge.net/stripes.tld"]]
- <html>
- <head>
- <title>My First Stripe</title>
- <style type="text/css">
- input.error { background-color: yellow; }
- </style>
- <script type="text/javascript" src="js/jquery.js"></script>
- <script type="text/javascript" src="js/general.js"></script>
-
- <script type="text/javascript">
- function submitForm(button) {
- var form = button.form;
- var params = $(form).serialize() + '&_eventName=' +
- button.name;
- var xhr = $.post(form.action, params, function(data) {
- if (xhr.getResponseHeader('AppSuccess')) {
- $('#form').hide();
- $('#people').html(data);
- }
- else {
- $('#form').html(data);
- }
- });
- return false;
- }
- </script>
-
-
- </head>
- <body>
- <h1>Stripes Calculator - FTL</h1>
-
- Hi, I'm the Stripes Calculator. I can only do addition. Maybe, some day, a
- nice programmer
- will come along and teach me how to do other things?
-
- <div id="people">
- </div>
-
- <div id="form">
- [#include "form.ftl"]
- </div>
-
- </body>
- </html>
-
- === Form page template: /WEB-INF/templates/frontend/form.ftl
- [#ftl]
- [#assign s=JspTaglibs["http://stripes.sourceforge.net/stripes.tld"]]
-
- [EMAIL PROTECTED]
beanclass="com.tehworld.bride.web.action.frontend.FormActionBean"]
- [EMAIL PROTECTED]/]
- [EMAIL PROTECTED] name="firstname"/]
- [EMAIL PROTECTED] name="lastname"/]
- [EMAIL PROTECTED] name="save" value="Save" onclick="return
submitForm(this);"/]
- [EMAIL PROTECTED] name="cancel" value="Cancel"/]
- [/@]
-
- === People Template: /WEB-INF/templates/frontend/people.ftl
- Just some text for People Template
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users