Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
Spring
display exception on formbackingobject
riccardo alfrilli
Greenhorn
Posts: 16
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all,
i want to display an exception occurred in the formbacking object.
new SimpleFormController.java
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.prova.spring; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.validation.BindException; import org.springframework.validation.BindingErrorProcessor; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; import org.springframework.web.util.WebUtils; /** * * @author AlfaOmega */ public class NewSimpleFormController extends SimpleFormController { private String viewName; public NewSimpleFormController() { //Initialize controller properties here or //in the Web Application Context //setCommandClass(MyCommand.class); //setCommandName("MyCommandName"); //setSuccessView("successView"); //setFormView("formView"); } @Override protected Object formBackingObject(HttpServletRequest request) throws Exception { int i = 0; List l = new ArrayList(); WebUtils.exposeErrorRequestAttributes(request, new Exception(""), "dispatcher-servlet"); BindException be = new BindException(l, "command"); be.reject("SONO QUI!"); return l; } @Override protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception { errors.reject("SONO QUI!"); } @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { int i = 0; errors.reject("SONO QUI!"); return super.onSubmit(request, response, command, errors); } /** * @return the viewName */ public String getViewName() { return viewName; } /** * @param viewName the viewName to set */ public void setViewName(String viewName) { this.viewName = viewName; } //Use onSubmit instead of doSubmitAction //when you need access to the Request, Response, or BindException objects /* @Override protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { ModelAndView mv = new ModelAndView(getSuccessView()); //Do something... return mv; } */ }
try.jsp
<%-- Document : try Created on : 8-ago-2010, 12.24.24 Author : AlfaOmega --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ page session="true"%> <%@ page import="java.util.List"%> <%@ page import="java.util.Hashtable"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> <form:form commandName="command" action="try.htm" method="post"> <div> <c:out value="${errors}"/> <span class="testo10">(*) Valorizzare uno dei campi di ricerca</span><br /> <spring:hasBindErrors name="command"> <p class="ERROREROSSO">Ci sono ${errors.errorCount} errore/i in totale:</p> <ul> <c:forEach var="errMsgObj" items="${errors.allErrors}"> <li class="ERROREROSSO"> <spring:message code="${errMsgObj.code}" text="${errMsgObj.defaultMessage}"/> </li> </c:forEach> </ul> </spring:hasBindErrors> </div> <div id="box-button"> <input type="submit" value="click me" name="click" /> </div> </form:form> </body> </html>
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Bind global errors to Spring form and throw them to view
Getting a headage..... Cannot find class [...] for bean with name '...' defined in ServletContext re
Spring problem (SimpleFormController)
Use of formBackedObject
Spring form input binding problem
More...