-
Troubles with SpringMVC
Hello.
I need to realize the next scheme:
1. There is an action FindFlightsController, that executes a searching of airplane flights.
Code:
public class FindFlightsController extends BaseFormController {
protected Object formBackingObject(HttpServletRequest request) throws Exception {
FlightRequestImpl flightRequest = new FlightRequestImpl();
flightRequest.setHasReturnFlight(true);
return flightRequest;
}
protected Map referenceData(HttpServletRequest request) throws Exception {
Collection cabinClasses = new ArrayList();
cabinClasses.add(ReservationService.ECONOMY_CLASS);
cabinClasses.add(ReservationService.BUSINESS_CLASS);
Map model = new HashMap();
model.put(WebAppConstants.CABIN_CLASSES_PARAM, cabinClasses);
return model;
}
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
Map model = new HashMap();
FlightRequest flightRequest = (FlightRequest) command;
Collection flights = getReservationService().getFlights(flightRequest);
if(null == flights || flights.size() < 1) {
return new ModelAndView(WebAppConstants.FLIGHT_NOT_FOUND_VIEW);
}
model.put(WebAppConstants.FLIGHTS_PARAM, flights);
return new ModelAndView(getSuccessView(), model);
}
}
It has next mapping:
Code:
<bean id="findFlightsController" class="FindFlightsController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>flightRequest</value></property>
<property name="commandClass"><value>FlightRequestImpl</value></property>
<property name="successView"><value>forward:ReserveFlight.htm</value></property>
<property name="formView"><value>FlightRequest</value></property>
<property name="validator"><bean class="FlightRequestValidator"/></property>
<property name="reservationService"><ref bean="reservationService"/></property>
</bean>
2. After ending of this action the page ViewFlights.jsp must be screened with founded flights. On the page it is necessary to select a flight and to reserve boarding seats in the flight.
Code:
<form action="<c:url value="/ReserveFlight.htm"/>" method="POST">
<h1>Avaible flights</h1>
<spring:bind path="flightReservation.flight">
<span class="fieldError"><c:out value="${status.errorMessage}"/></span>
<c:forEach items="${flights}" var="flight">
<input type="radio" name="<c:out value="${status.expression}"/>" value="<c:out value="${flight.flightCode}" />" <c:if test="${status.value eq flight.flightCode}" >checked</c:if>>
</c:forEach>
</spring:bind>
<a href="javascript:history.back();">back</a>
<input type="submit">
</form>
3. Seat reserving realizes ReserveFlightController.
Code:
public class ReserveFlightController extends BaseFormController {
protected Object formBackingObject(HttpServletRequest request) throws Exception {
return new FlightReservation();
}
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
FlightReservation flightReservation = (FlightReservation) command;
Flight flight = getReservationService().reserveFlight(flightReservation.getFlight());
Map model = new HashMap();
model.put(WebAppConstants.RESERVED_FLIGHT_PARAM, flight);
return new ModelAndView(getSuccessView(), model);
}
}
It has mapping:
Code:
<bean id="reserveFlightController" class="ReserveFlightController">
<property name="commandName"><value>flightReservation</value></property>
<property name="commandClass"><value>FlightReservation</value></property>
<property name="successView"><value>ReviewBooking</value></property>
<property name="formView"><value>ViewFlights</value></property>
<property name="validator"><bean class="FlightReservationValidator"/></property>
<property name="reservationService"><ref bean="reservationService"/></property>
</bean>
When a user made no selection and clicked the button ?Submit? the program has to screen error message and to show a list of free flights.
4. It should be screened a page with information about reserved flight.
5. It can be executed a jump to the start of searching with the link ?Back?.
And now some problems:
1. After ending of the action FindFlightsController it must be executed a forward to ReserveFlightController and screened a page ViewFlights.jsp. Right now a validation is made and it screens a message about selecting of no one flight, although it is just first page screening.
The question: how it can be corrected?
2. If you click ?Submit? after that without flight selection, the list of finding flights will be lost.
The question: how to avoid it?
3. When we?ll try to come back with the link javascript:history.back(), then we?ll find themselves at the page ViewFlights.jsp instead the page of flight searching.
The question: how we can to realize a correct return with saving of previous forms condition?[/code]
-
I've been experiencing the same problem. Has anybody found a fix/workaround?
Thanks!