You must be able to understand the execution principle and sequence of the Action class!

<1> Type conversion
       Type conversion failure occurs before Action calls setXxx() of the corresponding attribute. Type conversion failure does not affect the operation of the program.

<2> setXxx
       The setXxx() of the attribute will be executed regardless of whether the type conversion is successful or not, and the value of the corresponding attribute will be set to null when the type conversion fails.

<3> Data verification
       When the validator verifies the attribute value set by setXxx(), if the verification fails, the system will store the verification failure information in the fieldErrors collection. If all data is verified, there is abnormal information in the collection. (Ie fieldErrors.size()> 0), the workFlow interceptor will return "input" to forward the request to the input view. At this time, the request cannot reach the Action and cannot execute the method in it.
Insert picture description here

       If a type conversion exception has occurred before, the exception information will not only be included in the fieldErrors collection, but the system will also inherit the setXxx() of the attribute that failed to perform the conversion and set its value to null. The null value assigned to the attribute is not the user input Expected value, so the verification will fail during data verification, and the verification failure information at this time will also be written into the fieldErrors collection.

<4> Action method
       After the above steps, if there is abnormal information in the fieldErrors collection in the system, the system will automatically forward the request to the input view. If there is no abnormal information in the collection, the method in Action will be executed.

Guess you like

Origin blog.csdn.net/qq_44965393/article/details/111971797