Announcement Announcement Module
Collapse
No announcement yet.
Troubles with SpringMVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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&#40;null == flights || flights.size&#40;&#41; < 1&#41; &#123;
          	return new ModelAndView&#40;WebAppConstants.FLIGHT_NOT_FOUND_VIEW&#41;;
          &#125;
        model.put&#40;WebAppConstants.FLIGHTS_PARAM, flights&#41;;
    
        return new ModelAndView&#40;getSuccessView&#40;&#41;, model&#41;;
      &#125;
    &#125;
    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&#58;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&#58;url value="/ReserveFlight.htm"/>" method="POST">
          <h1>Avaible flights</h1>
          <spring&#58;bind path="flightReservation.flight">
            <span class="fieldError"><c&#58;out value="$&#123;status.errorMessage&#125;"/></span>
            <c&#58;forEach items="$&#123;flights&#125;" var="flight">
              <input type="radio" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;flight.flightCode&#125;" />" <c&#58;if test="$&#123;status.value eq flight.flightCode&#125;" >checked</c&#58;if>>
            </c&#58;forEach>
          </spring&#58;bind>
          <a href="javascript&#58;history.back&#40;&#41;;">back</a>      
          <input type="submit">
        </form>
    3. Seat reserving realizes ReserveFlightController.
    Code:
    public class ReserveFlightController  extends BaseFormController &#123;
    
      protected Object formBackingObject&#40;HttpServletRequest request&#41; throws Exception &#123;
        return new FlightReservation&#40;&#41;;
      &#125;
    
      public ModelAndView onSubmit&#40;HttpServletRequest request, HttpServletResponse response, Object command, BindException errors&#41; throws Exception &#123;
    
        FlightReservation flightReservation = &#40;FlightReservation&#41; command;
        Flight flight = getReservationService&#40;&#41;.reserveFlight&#40;flightReservation.getFlight&#40;&#41;&#41;;
    
        Map model = new HashMap&#40;&#41;;
        model.put&#40;WebAppConstants.RESERVED_FLIGHT_PARAM, flight&#41;;
        return new ModelAndView&#40;getSuccessView&#40;&#41;, model&#41;;
      &#125;
    &#125;
    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]

  • #2
    I've been experiencing the same problem. Has anybody found a fix/workaround?

    Thanks!

    Comment

    Working...
    X