Announcement Announcement Module
Collapse
No announcement yet.
does formcontroller support multiple successview? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • does formcontroller support multiple successview?

    I'm currently evaluating spring and has this question: Does spring web tier's formcontroller support map to multiple successview? e.g. a screen may route to different view base on some business logic in the controller, then how spring do that. Also how to define the mapping in xml?

    Thanks in advance for any reply.

    Rgds,
    Arthur

  • #2
    This is just simple IoC - I think the setSuccessView/getSuccessView methods are just added for convenience - you can add whatever views you want. Take a look at the SimpleFormController source and it should become clear.

    Comment


    • #3
      I get your point and you are correct. By looking into SimpleFormController, if you not return the ModelAndView, it will use the default: SuccessView. If it is not defined, exception will throw. However, I personally not prefer to define such mapping using private fields in the formcontroller as it require lot of typing (even eclipse help a lot in creating the getter/setter). It would be nice for me to just return the result action and the framework will redirect on behalf of me. (That's what our framework current does) However, spring has a nice thing which is the spring:bind in handling error of an input form. It is much clean.

      Comment


      • #4
        I personally not prefer to define such mapping using private fields in the formcontroller as it require lot of typing
        You could ue a Map.

        Comment


        • #5
          Your suggestion is much better as only one getter/setter require to define for each form on the action mapping. With defining a java editor template for this in eclipse will nearly solve the "typing issue". However, in terms of framework design, I still think it is the job of the framework to perform this and I just need to return the result action. sorry for this insist

          Comment


          • #6
            sorry for this insist
            No dramas

            I still think it is the job of the framework to perform this(map to multiple successview?)
            SimpleFormController is only a convenience class. If you think needs another, you can submit the one you are going to develop to JIRA for inclusion in future releases.

            Comment


            • #7
              The lines of interest are the adminView and waitlistView:
              Code:
                  <bean id="adminSignInCtlr" class="ctlr.AdminSignInCtlr">
                      <property name="commandClass" value="view.AdminSignInFrmData" />
                      <property name="validator" ref="adminSignInValidate" />
                      <property name="formView" value="adminSignInView" />
                      <property name="adminView" value="fdebugView" />
                      <property name="waitlistView" value="waitlistView" />
                      <property name="sessionForm" value="false" />
                      <property name="bindOnNewForm" value="true" />
                      <property name="facilityDao" ref="facilityDao" />
                      <property name="wleDao" ref="wleDao" />
                  </bean>
              This is a snippet of code from my SimpleFormController. Notice that the views it's returning correspond to the 2 properties I set up in the -servlet.xml file. So you can add your own views and have as many as you want your controller to branch to.
              Code:
                  private String      adminView;
                  private String      waitlistView;
              
              ...
                  protected ModelAndView
                  onSubmit&#40;Object cmd&#41; &#123;
              ...
                      if &#40;view.equals&#40;"admin"&#41;&#41;
                          return&#40;new ModelAndView&#40;adminView, "model", model&#41;&#41;;
              
                      if &#40;view.equals&#40;"waitlist"&#41;&#41;
                          return&#40;new ModelAndView&#40;waitlistView, "model", model&#41;&#41;;
              &#125;
              ...
                  public void
                  setAdminView&#40;String adminView&#41; &#123;
                      this.adminView = adminView;
                  &#125;
              
                  public void
                  setWaitlistView&#40;String waitlistView&#41; &#123;
                      this.waitlistView = waitlistView;
                  &#125;
              In the above java code "view" of view.equals( is the string data from a form field, it just happens to have the name of "view". I'm converting a legacy php app.
              Here's a partial listing of my source directory:
              Code:
              ./war/WEB-INF/jsp&#58;
              CVS/                  fdebugView.jsp        waitlistView2.jsp
              adminSignInView.jsp   include.jsp
              debugView.jsp         waitlistView.jsp

              Comment


              • #8
                Originally posted by lumpynose
                private String adminView;
                Originally posted by ArthurTam
                I personally not prefer to define such mapping using private fields in the formcontroller
                I don't think this is what ArthurTam is after.

                Comment


                • #9
                  you can submit the one you are going to develop to JIRA for inclusion in future releases.
                  I will try this and ask for your help (or post a question in this forum) if there is any problem in submitting things to JIRA as I'm new to this communities.


                  I don't think this is what ArthurTam is after.
                  katentim, you are right. lumpynose's suggestion was what I'm not prefer.

                  Comment

                  Working...
                  X