650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/140T01U3-0.png "" 807 "height =" 362 "/>
Command:
Public class RantsForVehicleController
Extends AbstractCommandController {
Public RantsForVehicleController (){
SetCommandClass (Vehicle. class );
SetCommandName ("vehicle ");
}
Protected ModelAndView handle (HttpServletRequest request,
HttpServletResponse response, Object command,
BindException errors) throws Exception {
Vehicle vehicle = (Vehicle) command;
List vehicleRants =
RantService. getRantsForVehicle (vehicle ));
Map model = errors. getModel ();
Model. put ("rants", 4
RantService. getRantsForVehicle (vehicle ));
Model. put ("vehicle", vehicle );
Return new ModelAndView ("vehicleRants", model );
}
650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/140T0C51-1.png "" 802 "height =" 350 "/>
Public AddRantFormController (){
SetCommandClass (Rant. class );
SetCommandName ("rant ");
}
Protected Object formBackingObject (HttpServletRequest request)
Throws Exception {
Rant rantForm = (Rant) super. formBackingObject (request );
RantForm. setVehicle (new Vehicle ());
Return rantForm;
}
Protected Map referenceData (HttpServletRequest request)
Throws Exception {
Map referenceData = new HashMap ();
ReferenceData. put ("states", ALL_STATES );
Return referenceData;
}
Protected ModelAndView onSubmit (Object command,
BindException bindException) throws Exception {
Rant rant = (Rant) command;
RantService. addRant (rant );
Return new ModelAndView (getSuccessView ());
}
Validator:
<Bean id = "addRantController"
Class = "com. roadrantz. mvc. AddRantFormController">
<Property name = "formView" value = "addRant"/>
<Property name = "successView" value = "rantAdded"/>
<Property name = "rantService" ref = "rantService"/>
<Property name = "validator">
<Bean class = "com. roadrantz. mvc. RantValidator"/>
</Property>
</Bean>
650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/140T03517-2.png "" 659 "height =" 271 "/>
Protected Object formBackingObject (HttpServletRequest request)
Throws Exception {
Motorist formMotorist = new Motorist ();
List <Vehicle> vehicles = new ArrayList <Vehicle> ();
Vehicles. add (new Vehicle ());
FormMotorist. setVehicles (vehicles );
Return formMotorist;
}
Protected Map referenceData (HttpServletRequest request,
Object command, Errors errors, int page) throws Exception {
Motorist motorist = (motorist) command;
Map refData = new HashMap ();
If (page = 1 & request. getParameter ("_ target1 ")! = Null ){
RefData. put ("nextVehicle ",
Motorist. getVehicles (). size ()-1 );
}
Return refData;
}
Protected void postProcessPage (HttpServletRequest request,
Object command, Errors errors, int page) throws Exception {
Motorist motorist = (Motorist) command;
If (page = 1 & request. getParameter ("_ target1 ")! = Null ){
Motorist. getVehicles (). add (new Vehicle ());
}
}
Protected ModelAndView processFinish (HttpServletRequest request,
HttpServletResponse response, Object command,
BindException errors)
Throws Exception {
Motorist motorist = (motorist) command;
// The last vehicle is always blank... remove it
Motorist. getVehicles (). remove (
Motorist. getVehicles (). size ()-1 );
RantService. addMotorist (motorist );
Return new ModelAndView (getSuccessView (),
"Motorist", motorist );
}
// Injected
Private RantService rantService;
Public void setRantService (RantService rantService ){
This. rantService = rantService;
}
// Returns the last page as the success view
Private String getSuccessView (){
Return getPages () [getPages (). length-1];
}
========================================================== ============================
To create Next
And Back buttons on the page, all you must do is create submit buttons that are
Appropriately named with the _ target prefix:
<Form method = "POST" action = "feedback.htm">
...
<Input type = "submit" value = "Back" name = "_ target0">
<Input type = "submit" value = "Next" name = "_ target2">
</Form>
========================================================== ============================
ThrowawayController is prototype.
========================================================== ======
<Bean id = "exceptionResolver" class = "org. springframework. web.
? Servlet. handler. SimpleMappingExceptionResolver ">
<Property name = "exceptionMappings">
<Props>
<Prop key = "java. lang. Exception"> friendlyError </prop>
</Props>
</Property>
</Bean>
====================================
Word:
Equanimity