(4) Form processing Action: PriceIncReaseformAction
Package web;
Import org.apache.commons.logging.log;
Import org.apache.commons.logging.logfactory;
Import bus.priceincrease;
Import Bus.ProductManager;
Import com.opensymphony.xwork.actionsupport;
Public class priceIncreaseformaction extends actionSupport {
/ ** Logger for this class and subclasses * /
Protected final log logger = logfactory.getlog (getclass ());
Private productManager product;
Private priceIncrease priceincrease;
Public String Execute () throws exception {
INT INCREASE = GetPriceIncrease (). getpercentage ();
Logger.info ("Increase PriceS By" Increase "%.");
Prodman.Increaseprice (Increase);
RETURN SUCCESS;
}
Public productManager getProdman () {
Return Prodman
}
Public void setProdman (ProductManager Productman) {
This.Prodman = product;
}
Public PriceInCrease getPriceIncRease () {
Return PriceinCrease;
}
Public void setPriceIncrease (PriceIncrease PriceIncrease) {
this.priceincrease = priceIncrease;
}
}
l PriceInCreaseformAction implements the same features as the PriceInCreaseformController, but you should be simple:
Ø Do not need to collect the data required by the result view, this is implemented by the SpringAppAction (see the configuration of PriceInCreaseFormAction)
Ø Data return function is implemented on the page
l PriceInCreaseFormAction Configure in xwork.xml
Class = "Web.PriceInCreaseformAction"> / web-inf / template / priceIncrease.vm param> result>
/ web-inf / jsp / priceIncrease.jsp param> result> -> SpringApp param> result> action> l l CHAIN type l l ExternalValidationWorkflowStack is defined in the previous Class = "com.opensymphony.xwork.interceptor.externalReference" /> interceptor-stack> interceptor-stack> interceptors> (5) Data validity verification l WebWork2 XWORK, using XWork's data validity verification mechanism l Xwork's Validation Framework allows you to apply Enter Authentication Rules to Action Before executing action l Register Validator: WW2 / Web-INF / CLASS / VALIDATORS.XML validators> Ø The top is some commonly used verification provided by Xwork and WebWork2, you can use it directly Ø Ø If the above verifier is not suitable, you can extend the verification framework of the XWork, custom verification, and register L activation verification in validators.xml: Ø For an action that requires data validity verification, you need to add a reference to ValidationInterceptor to the configuration. Ø The default ValidationWorkflowStack already contains references to the ValidationInterceptor, usually more is to add a ValidationWorkflowstack reference (as described in the Action Configuration in front) l Specify the verification rule (with the same directory with the Action class): PriceIncReaseformAction-Validation.xml Field-Validator> priceIncrease.percentage> 0 param> Field-Validator> 50 param> Field-Validator> field> validators> l Data verification rules definition in the XML file, the file name is an actionName-value.xml, where the actionname is the corresponding Action class name or its parent class name, naming rules Similar to the resource bundle l l l Error.Not-Specified = Percentage Not Specified !!! Error.Too-low = you have to specify a percentage higher Than $ {expression}%! Error.Too-high = don't be bigy - you can't raise price by more $ {max}%! l The message in the resource bundle can use the parameters of the validator using the form of $ {paramname}, but there is no use of other parameters, this is no Spring MVC Framework flexible l In addition, since WebWork2 is set to set attribute values, verify, for INT type properties, if null, automatically convert to 0, so there is not much significant for the first verification (What better way? Custom verifier)