Announcement Announcement Module
No announcement yet.
_target1 always returns zero Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • _target1 always returns zero

    Hi there,

    The problem I am having is that my first page in my wizard always returns 0. I have three pages each with submit buttons with names _target1, _target2 and _target3. Everything worked until today when I did some tinkering :oops:

    I use the default getTargetPage method and I can't getpast the first page. No error occurs when I click on the submit button with the name _target1 the page variable in the referenceData method is always zero, therefore the first page is re-displayed.

    I wanted to use the command object to propagate the values through the controller and its various pages instead of continually adding and retrieving the values from the model and request objects. I believed this to be a simple thing to do, and I still believe that, the problem is that I guess I am just as simple as once I tried it and broke the app, I couldn't revert to the working version(my fault for not versioning or backing up). I can't see anything wrong with the code as it stands, I have also checked it against an old version I backed up a couple of weeks ago and there is little difference. The JSP pages submit buttons correctly use _target1, _target2 etc as the name.

    Under what circumstances would the JSP always return a page number of zero? All code is below.

    public class BookingWizardController extends AbstractWizardFormController {
      private SalonFacadeIF salonFacade;
      public BookingWizardController() {
        // The command object will be included in the model under this name.
        // Set the wizard pages, i.e. the view names for the pages. 
        // The array index is interpreted as page number.
        setPages(new String[] { "stylistAndService", 
                                "confirmBooking" });
      protected Object formBackingObject(HttpServletRequest request) 
                                         throws Exception {
        System.out.println("formBackingObject method");
        // Get the users session.
        UserSession userSession = 
        // Get the user account from the users session.
        UserAccount userAccount = userSession.getAccount();
        if(userAccount != null) {
          // If there is a user account, create a reservation object.
          Reservation reservation = new Reservation();
          return reservation;
        // Create an error message.
        String message = 
         "A booking couldn't be created because a user account could not be found.";
        // Create and initialize a new model and view.
        ModelAndView modelAndView = new ModelAndView("Error", 
        // Display error view.
        throw new ModelAndViewDefiningException(modelAndView);
      protected boolean isFormSubmission(HttpServletRequest request) {
        System.out.println("isFormSubmission method");
        return super.isFormSubmission(request) || 
               request.getParameter(PARAM_FINISH) != null;
      protected void onBindAndValidate(HttpServletRequest request, 
                                       Object command, 
                                       BindException ex,
                                       int page) throws Exception {
        System.out.println("onBindAndValidate method");
        Reservation reservation = (Reservation)command;
        // If the page is the stylist and services page.
        if(page == 0) {
          System.out.println("page zero");
          System.out.println("parameter stylist is " + request.getParameter("stylist"));
          System.out.println("parameter service is " + request.getParameter("service"));
          System.out.println("parameter date is    " + request.getParameter("date"));
      protected Map referenceData(HttpServletRequest request,
                                  int page) 
                                  throws Exception {
        System.out.println("referenceData method");
        System.out.println("page = " + page);
        // If the page is the stylist and services page.
        if(page == 0) {
          System.out.println("Getting first page model");
          return getFirstPageModel();
        } else if(page == 1) { // Date and time page.
          System.out.println("Getting second page model");
    //    return getSecondPageModel(request, reservation);
          return getSecondPageModel(request);
        } else if(page == 2) { // Confirmation page.
          System.out.println("Getting third page model");
          return getThirdPageModel(request);
        return null;
    The getFirstPageModel() etc methods are private methods that construct the model Maps.
      public void setSalonFacade(SalonFacadeIF facade) {
        System.out.println("setSalonFacade method");
        this.salonFacade = facade;
      protected void validatePage(Object command, Errors errors, int page) {
        System.out.println("validatePage method");
        if(page == 0) {
          System.out.println("validating first page.");
        } else if(page == 1) {
          System.out.println("validating second page.");
      protected ModelAndView processFinish(HttpServletRequest request,
                                           HttpServletResponse response, 
                                           Object command, 
                                           BindException ex)
                                           throws Exception {
        System.out.println("processFinish method");
        Map model = new HashMap();
        return new ModelAndView("acknowledgeBooking", model);
      protected ModelAndView processCancel(HttpServletRequest request, 
                                           HttpServletResponse response,
                                           Object command, 
                                           BindException errors) 
                                           throws Exception {
        System.out.println("processCancel method");
        throw new UnsupportedOperationException();
    } // End of class
    <%@ page session="false" %>
    <%@ taglib prefix="c" uri="http&#58;//" %>
    <%@ taglib prefix="fmt" uri="http&#58;//" %>
    <fmt&#58;setLocale value="en-UK" />
    <form name="stylistAndService" 
      <table border="1" align="center" width="65%">
          <td colspan="3" align="left">
            <img src="./images/ban_booking.jpg" border="0"/>
          <td colspan="2" align="center">
            <select name="stylist">
              <c&#58;forEach var="stylist" items="$&#123;stylists&#125;">
                <option><c&#58;out value="$&#123;stylist.fullName&#125;"/></option>
          <td colspan="2" align="center"> 
            <select name="service">
              <c&#58;forEach var="service" items="$&#123;services&#125;">
                  <c&#58;out value="$&#123;;"/> - 
                  <fmt&#58;formatNumber value="$&#123;service.cost&#125;" type="currency"/>
          <td align="center"> 
            <select name="date"><!--
              <c&#58;forEach var="date" items="$&#123;dates&#125;">
                  <!-- i.e. 29/11/2004 --><!--
        	        <fmt&#58;formatDate value="$&#123;date&#125;" 
              <!-- FOR TESTING PURPOSES -->
          <td colspan="3" align="center">
            <input type="submit" name="_target1" value="search">
          <td colspan="2" align="right">
            <img src="./images/ban_bottom.jpg" border="0"/>