Java Reference
In-Depth Information
Line 29 : The BookValidator class is injected using the setter method.
Line 63 : In processSubmit() , validate() of the BookValidator is called to check
whether the book details are entered by the user. validate() is passed the value
of the Book model and the BindingResult object to hold errors, if any.
Line 66 : A check is made whether the result variable holds any errors. If there
are errors, then the application displays the same page with the error messages.
If there are no errors, that is, the user has entered all the correct data, then the
application displays the list of the book details along with the newly entered
book details.
Configuring the Validator
Now you have to declare the validator for the URL addBook.html in bookstore-servlet.xml , as illustrated
in Listing 5-52.
Listing 5-52. Declaring the BookValidator
1. <?xml version="1.0" encoding="UTF-8"?>
2. <beans:beans xmlns=" http://www.springframework.org/schema/mvc "
3. xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xmlns:beans=
" http://www.springframework.org/schema/beans "
4. xmlns:context=" http://www.springframework.org/schema/context "
5. xsi:schemaLocation=" http://www.springframework.org/schema/mvc http://www.springframework.org/
schema/mvc/spring-mvc.xsd
6. http://www.springframework.org/schema/beans http://www.springframework.org/schema/
beans/spring-beans.xsd
7. http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd " >
8.
9. <!-- DispatcherServlet Context: defines this servlet's request-processing
10. infrastructure -->
11.
12. <context:component-scan base-package="com.apress.bookstore.controller" />
13. <beans:bean class="com.apress.bookstore.validator.BookValidator" />
14.
15. <!-- Resolves views selected for rendering by @Controllers to .jsp resources
16. in the /WEB-INF/views directory -->
17. <beans:bean
18. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
19. <beans:property name="prefix" value="/WEB-INF/views/" />
20. <beans:property name="suffix" value=".jsp" />
21. </beans:bean>
22. </beans:beans>
Line 13 : The BookValidator class is defined. The container creates the
BookValidator class by calling its constructor.
 
 
Search WWH ::




Custom Search