font>
td>
spring: bind>
TR>
TABLE>
please fix all errors! b>
Spring: HasbinderRors>
form>
> Home
body>
html>
7. SimpleFormController's operation mechanism, said, for example, SpringAppController, only exercising page process control and model generation, all of which are not related to the FORM of the page, which means that the submission data from the page is not accepted.
To handle the submission of the page, let Controller inherit from SimpleFormController.
The usual SimpleFormController is defined as follows:
Public Class PriceIncreaseformController Extends SimpleFormController {
Private productManager product;
Public ModilandView OnSubmit (Object Command)
Throws servletexception {
INT INCREASE = (PriceInCrease) Command .GetPercentage ();
Prodman.Increaseprice (Increase);
String now = (New java.util.date ()). TOSTRING ();
Map mymodel = new hashmap ();
MyModel.Put ("now", now);
MyModel.put ("Products", getProductManager (). getProducts ());
Return New ModelandView (New RedirectView ()));
}
Protected Object FormBackingObject (httpservletRequest Request) throws servletexception {
PriceIncrease priceIncrease = new priceIncrease ();
PriceinCrease.setpercentage (20);
Return PriceinCrease;
}
Public Void SetProductManager (ProductManager PM) {
PRODMAN = PM;
}
Public productManager getProductManager () {
Return Prodman
}
}
The difference between Controller is more than 2 methods:
Public ModilandView OnSubmit (Object Command)
Protected Object FormBackingObject (httpservletRequest Request) THROWS ServleTexception
Before understanding SimpleFormController, let's take a look at SpringApp-servlet.xml definitions for SimpleFormController:
True value> property>
priceIncrease value> property>
bus.priceincrease value> proty> property>
priceIncrease value> property>
Hello.htm value> property>
Property>
bean>
These definitions are very understanding, of which 2 lines:
priceIncrease value> property>
bus.priceincrease value> property>
It is pointed out the class of the element of the corresponding page form and its real case object name. (I don't want to use Command, not Form, probably think that submission is command)
SpringApp-servlet.xml is as follows:
PriceIncReaseform prop>
prOPS>
Property>
bean>
Let's take a look at the operation mechanism of SimpleFormController:
Since it is also a Controller, its loading mechanism is the same as other controller. For example, the member property is also automatically initialized.
When the page request is handed over to the PriceInCreaseformController process, it first calls the FormBackingObject () method, which is the BEAN corresponding to the page FORM element and assigns the initial value. After completing, you will generate a page display.
When the user submits FORM, servlet does not run the PriceInCreaseformController. OnSubmit (), but first run the Support () and Validate (Object Obj, Erroors Erroors) method of the PriceInCreasevalidator. If there is a data error during the verification process (ie, if there is a data error, the error () method assigns the ERRORS.RejectValue () method. [Errors.rejectValue () method to be studied] Once the servlet is found in ERRORS, it will abort the program running directly to the original page, and some of the values stored in Errors can be displayed in the page.
If the verification is passed, the onSubmit method of SimpleFormController will start, and its return value is the page that will go.
Summarize a full process of the operation of SimpleFormController:
Servlet Request -> SimpleFormController.FormBackingObject () -> Show page -> Submit page -> SimpleFormController Validator.validate () -> SimpleFormController. onSubmit () -> View
转载请注明原文地址:https://www.9cbs.com/read-110493.html
|