Announcement Announcement Module
Collapse
No announcement yet.
AbstractWizardFormController - unable to go to page 3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractWizardFormController - unable to go to page 3

    Hi

    I have a problem with Wizard Form controller.
    I seem to not be able to progress past page 2 (_target1) in the flow, when i try to go to page 3 (_target2) then i end up at the initial page, just like when i started the flow(meaning the form is empty)

    I've tried almost everything i can think of, so i hope someone can help me find my mistake.

    Here is my controller:

    Code:
    public class MenuitemsWizard extends AbstractWizardFormController {
        private static Category log = Category.getInstance(MenuitemsWizard.class);
        private DataDao dataDao;
    
    
        public MenuitemsWizard() {
            super();
            setCommandClass(DbMenuItem.class);
            setPages(new String[]{"addMenuItem", "addMenuItem2", "addMenuItem3"});
        }
    
        public DataDao getDataDao() {
            return dataDao;
        }
    
        public void setDataDao(DataDao datadao) {
            this.dataDao = datadao;
        }
    
        public void afterPropertiesSet() {
            if (this.dataDao == null) {
                throw new IllegalArgumentException("'dao' is required");
            }
        }
    
    
        protected Object formBackingObject(HttpServletRequest request) throws ServletException {
            // get the MenuItem referred to by id in the request
            DbMenuItem art = getDataDao().getMenuById(RequestUtils.getStringParameter(request, "id", "0"));
            if (art == null) {
                art = new DbMenuItem();
            }
            return art;
        }
    
        protected ModelAndView processFinish(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, BindException e) throws Exception {
            DbMenuItem item = (DbMenuItem) o;
            dataDao.persist(item);
            Map model = new HashMap();
            model.put("order", item);
            model.put("message", "Menu item has been saved.");
            return new ModelAndView("succesView", model);
    
        }
    
        protected void validatePage(Object o, Errors errors, int i) {
            log.debug("called validatePage : " + i);
        }
    
        protected Map referenceData(HttpServletRequest request, int i)
                throws Exception {
            Map map = new java.util.HashMap();
            List artikler = getDataDao().getAllArticles();
            List content = getDataDao().getAllContent();
            map.put("contents", content);
            map.put("articles", artikler);
            map.put("editable", new Boolean(true));
            switch (i) {
                case 0:
                    List templates = getDataDao().getAllTemplates();
                    List news = getDataDao().getNewsItems();
                    List menuitems = getDataDao().getMenuItems();
                    List position = new ArrayList(2);
                    position.add("left");
                    position.add("right");
                    map.put("templates", templates);
                    map.put("news", news);
                    map.put("menuitems", menuitems);
                    break;
                case 1:
                    DbMenuItem item = (DbMenuItem) super.getCommand(request);
                    if (item == null || item.getParentElement() == null) {
                        log.warn("item or parent == null");
                        return map;
                    }
                    HibernateUtil.getSession().lock(item.getParentElement(), LockMode.NONE);
                    if (!Hibernate.isInitialized(item.getParentElement().getChildElements())) {
                        log.debug("Initializing childelements ");
                        Hibernate.initialize(item.getParentElement().getChildElements());
                    }
                    map.put("siblings", item.getParentElement().getChildElements());
                    break;
                case 2:
                    map.put("editable", new Boolean(false));
                    break;
                default:
                    break;
            }
            return map;
    
        }
    
        protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
            dateFormat.setLenient(false);
            binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
            binder.registerCustomEditor(DbTemplate.class, new TemplatePropertyEditor(getDataDao()));
            binder.registerCustomEditor(DbMenuItem.class, new MenuItemPropertyEditor(getDataDao()));
            binder.registerCustomEditor(Content.class, new ContentPropertyEditor(getDataDao()));
        }
    
    
    }
    The bean definition:
    Code:
    <bean id="addMenuItemFormtest" class="dk.msw.solutionworks.controller.MenuitemsWizard">
        <property name="validator">
            <ref local="menuItemValidator"/>
        </property>
        <property name="dataDao">
            <ref bean="dataDao"/>
        </property>
        <property name="pageAttribute"><value>currentPage</value></property>
    
    </bean>
    Im using a simple url handler mapping :
    Code:
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="/admin/addMenuItemTest.form">addMenuItemFormtest</prop>
                </props>
            </property>
        </bean>
    I am using a ResourceBundleViewResolver with the following view definitions :
    Code:
    addMenuItem.class=org.springframework.web.servlet.view.JstlView
    addMenuItem.url=/admin/addMenuItemForm.jsp
    addMenuItem2.class=org.springframework.web.servlet.view.JstlView
    addMenuItem2.url=/admin/addMenuItemForm2.jsp
    addMenuItem3.class=org.springframework.web.servlet.view.JstlView
    addMenuItem3.url=/admin/addMenuItemForm3.jsp
    And finally this is the second page in the flow:

    Code:
    <%@ include file="/admin/includes.jsp" %>
    <%@ include file="/admin/header.jsp" %>
    <%@ include file="/admin/debugParams.jsp" %><P>
    <P/>
    <H2><c&#58;if test="$&#123;command.new&#125;">Nyt </c&#58;if>menupunkt&#58;</H2>
    <spring&#58;bind path="command">
      <FONT color="red">
        <B><c&#58;out value="$&#123;status.errorMessage&#125;"/></B>
      </FONT>
    </spring&#58;bind>
    <P>
    <FORM  method="POST">
      <jsp&#58;include page="/admin/fields/title.jsp"/>
      <jsp&#58;include page="/admin/fields/contentList.jsp"/>
      <jsp&#58;include page="/admin/fields/showParentMenuItem.jsp"/>
      <jsp&#58;include page="/admin/fields/siblinglist.jsp"/>
    
      <c&#58;if test="$&#123;command.new&#125;">
        <input type="submit" value="N&ealig;ste" name="_target2"  />
      </c&#58;if>
      <c&#58;if test="$&#123;!command.new&#125;">
        <inputtype="submit" value="Update Menupunkt" name="_target2" />
      </c&#58;if>
    
    </FORM>
    <P>
    <BR>
    
    <%@ include file="/admin/footer.jsp" %>
    The third page is very similar to page 2:
    Code:
    <%@ include file="/admin/includes.jsp" %>
    <%@ include file="/admin/header.jsp" %>
    <P/>
    <H2><c&#58;if test="$&#123;command.new&#125;">Nyt </c&#58;if>menupunkt&#58;</H2>
    <spring&#58;bind path="command">
      <FONT color="red">
        <B><c&#58;out value="$&#123;status.errorMessage&#125;"/></B>
      </FONT>
    </spring&#58;bind>
    <P>
    
      <jsp&#58;include page="/admin/fields/title.jsp"/>
      <jsp&#58;include page="/admin/fields/contentList.jsp"/>
      <jsp&#58;include page="/admin/fields/menuitems.jsp"/>
      <jsp&#58;include page="/admin/fields/title.jsp"/>
      <jsp&#58;include page="/admin/fields/contentList.jsp"/>
      <jsp&#58;include page="/admin/fields/showParentMenuItem.jsp"/>
      <jsp&#58;include page="/admin/fields/siblinglist.jsp"/>
      <FORM method="POST">
      <input type="hidden" name="_finish" value="true"/>
      <c&#58;if test="$&#123;command.new&#125;">
        <INPUT type = "submit" value="Add Menupunkt" name="_finish"  />
      </c&#58;if>
      <c&#58;if test="$&#123;!command.new&#125;">
        <INPUT type = "submit" value="Update Menupunkt" name="_finish"  />
      </c&#58;if>
    </FORM>
    <P>
    <BR>
    
    <%@ include file="/admin/footer.jsp" %>
    I really hope that im just making some stupid mistake ;o) but i have spendt a lot of time on this now ... toomuch time considering the complexity of the forms them selves.

    Thanks
    Timm[/code]

  • #2
    I am using AbstractWizardFormController in my current project. I noticed that for the bean id "addMenuItemFormtest", all the list of pages is not mentioned.
    Given below is the bean definition from my project.

    Code:
    	<bean id="SubmitNewRequestController"
    		class="com.mycompany.SubmitNewRequestController"
    		>
    		<property name="pages">
    			<list>
    				<value>submitter_newRequest_0</value>
    				<value>submitter_newRequest_1</value>
    				<value>submitter_newRequest_2</value>
    			</list>
    		</property>
    	</bean>

    Comment


    • #3
      Hi neraj_cmu
      Thanks for the swift reply.

      I set the pages in the constructor like this:
      Code:
      setPages&#40;new String&#91;&#93;&#123;"addMenuItem", "addMenuItem2", "addMenuItem3"&#125;&#41;;
      I know that it uses them, since if i swap page 2 and 3 then i see page 3 as page 2 (hmm hope that made sense)

      But i will try and set them like you do, to see if it has any effect.

      Comment


      • #4
        Sorry, I missed that. Try overwriting onbindandvalidate and print out the value of page number. This is just to make sure that the page number is progressing to higher order from click to click.

        Comment


        • #5
          Hi again

          I have tried to set the pages like you suggested, and i have overriden onBindAndValidate and getTargetPage.

          What i can see now is that onBindAndValidate is only called when i go from page 1 to page 2 in the flow and it is called with pagenr 0.

          getTargetPage is also only called when i go from page 1 to page 2 and the values seem to be ok (called with page nr 0 and would return 1 ).

          I do not understand why these methods are not called when i go from page 2 to page 3.

          It seems that it think its supposed to show a brand new form !!!
          If I remove the view definition for page 3, then nothing changes, wich can only mean that it never look for page 3 in the flow.

          This has not got me much further .... I still have no idea what is going wrong, so any and all input is greatly appreciated.

          Thanks
          Timm

          Comment


          • #6
            Hi again

            I finally found out why it dident go past page 2 in the flow!!!

            It is all due to this small bit of code in the referenceData method :
            Code:
            DbMenuItem item = &#40;DbMenuItem&#41; super.getCommand&#40;request&#41;;
            This will in fact cause the object to get removed from the session, wich will cause the wizard to regard the submission for page 3 to be an invalidSubmission.
            It doas actually say in the api documentation for getCommand in AbstractFormController, that the command object gets removed from the session.
            Tho I doubt that they had intended for it to have this side effect ;o)

            Well anyway the code to use instead is the following :
            Code:
            DbMenuItem item = &#40;DbMenuItem&#41; request.getSession&#40;&#41;.getAttribute&#40;super.getFormSessionAttributeName&#40;&#41;&#41;;
            this seems to work for me.

            On a side note, this change seems to have removed a problem where i wasnt able to submit directly to the processFinish form method from a wizard form. (Think i saw other post about that on the forum).

            Regards
            /Timm

            Comment

            Working...
            X