Results 1 to 7 of 7

Thread: Wrong page is used with AbstractWizardFormController?

  1. #1
    Join Date
    Dec 2004
    Posts
    3

    Default Wrong page is used with AbstractWizardFormController?

    I have a controller that extends AbstractWizardFormController and for that I have 2 views/pages, configured like this:
    Code:
    <bean name="/send.htm" class="dk.mobilethink.bulk.controllers.SendController">
     <property name="pages">
      <list>
       <value>send_operator</value>
       <value>send_setting</value>
      </list>
     </property>
     <property name="properties"><ref bean="properties"/></property>
     <property name="commandClass">
      <value>dk.mobilethink.bulk.commands.SendCommand</value>
     </property>
    </bean>
    I also have a:
    Code:
    int targetPage = getTargetPage&#40;request, getCurrentPage&#40;request&#41;&#41;;
    System.out.println&#40;"targetPage&#58; "+targetPage&#41;;
    in my controller, and that prints out page 1, but no matter what the page shown is always my send_operator and never my send_setting, how can this be, what goes wrong here?

    Any hints are welcome.

    Best regards
    Søren

  2. #2
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default

    Please post your JSP code, especially form and submit buttons.

  3. #3
    Join Date
    Dec 2004
    Posts
    3

    Default Here are my code

    I have this "top" code first of all:
    Code:
    <%@ page contentType="text/html;charset=ISO-8859-1" %>
    <%@ taglib prefix="c" uri="http&#58;//java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http&#58;//java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix="fn" uri="http&#58;//java.sun.com/jsp/jstl/functions" %>
    <%@ taglib prefix="x" uri="http&#58;//java.sun.com/jsp/jstl/xml" %>
    <%@ taglib prefix="spring" uri="http&#58;//www.springframework.org/tags" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http&#58;//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http&#58;//www.w3.org/1999/xhtml">
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    		<title>Bulk OTA Configurator</title>
    		<script type="text/javascript" src="javascript/bulk.js"></script>
    	</head>
    	<body>
    	
    		<form action="send.htm" method="post">
    			<input type="hidden" id="target"/>
    			<select name="vendor" id="vendor" onchange="gotoPage&#40;this&#41;">
    				<option value="vendor">Select Vendor</option>
    				<c&#58;forEach items="$&#123;otaserverDevices&#125;" var="otaserverDevice">
    				<option value="$&#123;otaserverDevice.key&#125;"<c&#58;if test="$&#123;otaserverDevice.key == command.vendor&#125;"> selected="selected"</c&#58;if>>$&#123;otaserverDevice.key&#125;</option>
    				</c&#58;forEach>
    			</select>
    			<br/>
    			<select name="model" id="model" onchange="gotoPage&#40;this&#41;">
    				<option value="model">Select Model</option>
    				<c&#58;forEach items="$&#123;otaserverDevices&#91;command.vendor&#93;&#125;" var="otaserverDevice">
    				<option value="$&#123;otaserverDevice.key&#125;"<c&#58;if test="$&#123;otaserverDevice.key == command.model&#125;"> selected="selected"</c&#58;if>>$&#123;otaserverDevice.key&#125;</option>
    				</c&#58;forEach>
    			</select>
    		</form>
    And then this pages is the only page I can get shown "includes the top code":
    Code:
    <%@ include file="/WEB-INF/jsp/send_top.jsp" %>
    
    		<form action="send.htm" method="post">
    			<input type="hidden" id="target_op"/>
    			<br/>
    			<select name="operator" id="operator" onchange="gotoPage&#40;this&#41;">
    				<option value="operator">Select Operator</option>
    				<c&#58;forEach items="$&#123;managerUserNames&#125;" var="managerUserName">
    				<option value="$&#123;managerUserName&#125;"<c&#58;if test="$&#123;managerUserName == command.operator&#125;"> selected="selected"</c&#58;if>>$&#123;managerUserName&#125;</option>
    				</c&#58;forEach>
    			</select>
    			<br/>
    			<select name="setting">
    				<option value="setting">Select Setting</option>
    			</select>
    			<br/>
    			<select name="bearer">
    				<option value="bearer">Select Bearer</option>
    			</select>
    			<br/>
    			<input type="text" name="msisdn"/>
    			<br/>
    			<input type="text" name="msisdnFile"/>
    			<br/><br/>
    			<input type="submit" value="Log in"/>
    		</form>
    	</body>
    </html>
    And here is the page that does not get shown:
    Code:
    <%@ include file="/WEB-INF/jsp/send_top.jsp" %>
    
    		<form action="send.htm" method="post">
    			<input type="hidden" id="target_se"/>
    			<br/>
    			<select name="operator" id="operator" onchange="gotoPage&#40;this&#41;">
    				<option value="operator">Select Terminator</option>
    				<c&#58;forEach items="$&#123;managerUserNames&#125;" var="managerUserName">
    				<option value="$&#123;managerUserName&#125;"<c&#58;if test="$&#123;managerUserName == command.operator&#125;"> selected="selected"</c&#58;if>>$&#123;managerUserName&#125;</option>
    				</c&#58;forEach>
    			</select>
    			<br/>
    			<select name="setting" id="setting" onchange="gotoPage&#40;this&#41;">
    				<option value="setting">Select Setting</option>
    				<c&#58;forEach items="$&#123;settings&#125;" var="managerSetting">
    				<option value="$&#123;managerSetting&#125;"<c&#58;if test="$&#123;managerSetting == command.setting&#125;"> selected="selected"</c&#58;if>>$&#123;managerSetting.name&#125;</option>
    				</c&#58;forEach>
    			</select>
    			<br/>
    			<select name="bearer">
    				<option value="bearer">Select Bearer</option>
    			</select>
    			<br/>
    			<input type="text" name="msisdn"/>
    			<br/>
    			<input type="text" name="msisdnFile"/>
    			<br/><br/>
    			<input type="submit" value="Log in"/>
    		</form>
    	</body>
    </html>
    Here is my JavaScript that sets the page number:

    Code:
    function gotoPage&#40;src&#41; &#123;
    	var name = src.name;
    	var index = src.selectedIndex;
    	var page = 0;
    	var target = document.getElementById&#40;"target"&#41;;
    	switch &#40;name&#41; &#123;
    		case "vendor"&#58;
    			page = 0;
    			break;
    		case "model"&#58;
    			page = 0;
    			break;
    		case "operator"&#58;
    			page = 1;
    			target = document.getElementById&#40;"target_op"&#41;;
    			break;
    		default&#58;
    			page = 0;
    	&#125;
    	target.name = "_target" + page;
    	target.value = "dummy";
    	src.form.submit&#40;&#41;;
    &#125;
    I hope this helps, if not let me know what else you need.

  4. #4
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default

    I had some trouble getting my head around the AbstractWizardFormController as well, so I hope this helps.

    I think your code as posted looks ok, just one question: where did you use:

    Code:
    int targetPage = getTargetPage(request, getCurrentPage(request)); 
    System.out.println("targetPage: "+targetPage);
    If you did override the getTargetPage(HttpServletRequest request,
    int currentPage) method, then I think this could be the culprit - try removing the implementation and rely on the default behaviour provided in the super class.

    See: http://forum.springframework.org/sho...r mcontroller
    Last edited by robyn; May 14th, 2006 at 05:29 PM.

  5. #5
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    Seems like you're fighting AbstractWizardFormController...maybe for some good reason (?), but I noticed you're not specifying a pageAttribute property in you Spring config for the wizard.

    Look at the code for AbstractWizardFormController. If you declare:

    <property name="pageAttribute"><value>currentPage</value></property>

    then you'll be able to access this in your JSP page, and +1/-1 to go forward/back.

    You don't need any Javascript or anything to deal with page numbers, and can use JSTL or something to build the submit button names,

    e.g.

    <input type="submit" name="<c:out value='${currentPage + 1}'/>" value="Next"/>

    Are you trying to do anything tricky navigation-wise above and beyond just moving through the wizard pages?

  6. #6
    Join Date
    Dec 2004
    Posts
    3

    Default It is a little special

    The thing is, that on my wizard, it must be possible at any time to change any of the above choices and then jump back to the correct page that originally involved this choice, and thats why i have the JavaScript, so that the onchange triggers a specified page.

    Did that make sense?

    So... Should this not work, or what am i missing?

  7. #7
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    Sounds like you possibly should be overriding getTargetPage in AbstractWizardFormController...

    here's the code comment for the method.

    Code:
    Default implementation delegates to getTargetPage&#40;HttpServletRequest, int&#41;.
    Subclasses can override this for customized target page determination.
    e.g.

    The following JSP button on any page

    <input type="submit" name="_myFunkyNavigation" value="Blah"/>

    and the following code in getTargetPage(...)

    if(request.getParameter("_myFunkyNavigation") != null) {
    return 0;
    }

    will cause the first page of the wizard to be displayed.


    I don't think "MVC" means that you use Javascript to be the controller. You should try to put controller code in the controller. Post some token back to the controller to indicate some type of action you want to perform and then let the controller, not some javascript, decide where to go.

    Hope that helps.

Similar Threads

  1. Replies: 3
    Last Post: Sep 22nd, 2005, 10:14 AM
  2. Replies: 0
    Last Post: Jun 10th, 2005, 08:22 AM
  3. Replies: 0
    Last Post: May 24th, 2005, 01:44 AM
  4. Replies: 2
    Last Post: May 13th, 2005, 05:42 AM
  5. Replies: 1
    Last Post: Jan 24th, 2005, 04:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •