Hi Paolo,
What happens here is that both forms target the same page, they're using
pre-execution and returning redirects so everything is fine until you add
validation and instead of returning a redirect return a view with validation
errors. Then the page is rendered in its entirety including the second
controller. The second controller sees that its a POST request and treats it as
if its form was submitted.
The way you solve this is by treating the request as a form submission and do
validation only during pre-execution. Then a POST request not during
pre-execution instead renders the form as it would for a GET request.
This is an example of ContactFormComponent from the Blossom sample using this
technique:
[code]
@RequestMapping(value = "/contact", method = RequestMethod.GET)
public String viewForm(@ModelAttribute ContactForm contactForm) {
return "components/contactForm.ftl";
}
@RequestMapping(value = "/contact", method = RequestMethod.POST)
public String handleSubmit(@ModelAttribute ContactForm contactForm,
BindingResult result, Node content) throws RepositoryException {
PreexecutionContext preexecutionContext =
PreexecutionContextHolder.get(MgnlContext.getWebContext().getRequest());
if (preexecutionContext == null ||
!preexecutionContext.getUuid().equals(MgnlContext.getAggregationState().getCurrentContentNode().getIdentifier()))
return viewForm(contactForm);
new ContactFormValidator().validate(contactForm, result);
if (result.hasErrors()) {
return "components/contactForm.ftl";
}
return "website:" + content.getProperty("successPage").getString();
}
[/code]
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=41c73e9d-3543-4218-893e-b79d0933212f
----------------------------------------------------------------
For list details, see: http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------