Sunday, 15 September 2013

Who implemente the spring BindingResult? -



Who implemente the spring BindingResult? -

i'm new spring mvc , i'm trying understand next code

package com.companyname.springapp.web; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.validation.bindingresult; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import javax.servlet.servletexception; import javax.servlet.http.httpservletrequest; import javax.validation.valid; import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory; import com.companyname.springapp.service.priceincrease; import com.companyname.springapp.service.productmanager; @controller @requestmapping(value="/priceincrease.htm") public class priceincreaseformcontroller { /** logger class , subclasses */ protected final log logger = logfactory.getlog(getclass()); @autowired private productmanager productmanager; @requestmapping(method = requestmethod.post) public string onsubmit(@valid priceincrease priceincrease, bindingresult result) { if (result.haserrors()) { homecoming "priceincrease"; } int increment = priceincrease.getpercentage(); logger.info("increasing prices " + increment + "%."); productmanager.increaseprice(increase); homecoming "redirect:/hello.htm"; } @requestmapping(method = requestmethod.get) protected priceincrease formbackingobject(httpservletrequest request) throws servletexception { priceincrease priceincrease = new priceincrease(); priceincrease.setpercentage(15); homecoming priceincrease; } public void setproductmanager(productmanager productmanager) { this.productmanager = productmanager; } public productmanager getproductmanager() { homecoming productmanager; } }

as far know bindingresult interface , onsubmit method receives bindingresult object. don't understand is: implemented interface create object , implementation?

here servlet xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <bean id="productmanager" class="com.companyname.springapp.service.simpleproductmanager"> <property name="products"> <list> <ref bean="product1"/> <ref bean="product2"/> <ref bean="product3"/> </list> </property> </bean> <bean id="product1" class="com.companyname.springapp.domain.product"> <property name="description" value="lamp"/> <property name="price" value="5.75"/> </bean> <bean id="product2" class="com.companyname.springapp.domain.product"> <property name="description" value="table"/> <property name="price" value="75.25"/> </bean> <bean id="product3" class="com.companyname.springapp.domain.product"> <property name="description" value="chair"/> <property name="price" value="22.79"/> </bean> <bean id="messagesource" class="org.springframework.context.support.resourcebundlemessagesource"> <property name="basename" value="messages"/> </bean> <!-- scans classpath of application @components deploy beans --> <context:component-scan base-package="com.companyname.springapp.web" /> <!-- configures @controller programming model --> <mvc:annotation-driven/> <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="viewclass" value="org.springframework.web.servlet.view.jstlview"></property> <property name="prefix" value="/web-inf/views/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>

i don't if helps i'm using tomcat 7.0 , whole code in here: http://docs.spring.io/docs/spring-mvc-step-by-step/

who implemented interface create object , implementation?

implemented in spring framework , instantiated context. in above illustration beanpropertybindingresult.class exact implementation of bindingresult instantiated http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/validation/beanpropertybindingresult.html

spring-mvc

No comments:

Post a Comment