Announcement Announcement Module
Collapse
No announcement yet.
Now what? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Now what?

    I've just completed the MVC tutorial that links off the documentation page. To be honest, I feel like I've just taken a long bus ride, and have been let off in the middle of nowhere. The tutorial let me write/process a form page, but did little to tell me what's going on behind the scenes (what methods are being called when), and it didn't give me enough information to proceed with my own, simple, real world experiments. What's the next step after the tutorial?

    Also, some questions off the tutorial. First, in springapp-servlet.xml, in the urlMapping bean configuration, it uses <props> tags, which in turn use a prop attribute. I can figure out the <prop key=""> part, but what/where is the value between the opening and closing prop tag used? Is it just a description that can be used anywhere, or does it actually have some meaning?

    Next, in the onSubmit method of PriceIncreaseFormController, there's a line that sets the string "now" to a new date, but nowhere does it add it to the Model. Is this supposed to be done automatically, or is there an error in the example? I ask because I modified the string, but the modified string never shows up on the redirect page.

    Thx.

  • #2
    the value for the prop tags is the name of the bean you what to handle a request to a url(which is represented as the key)

    Code:
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="test.do">myController</prop>
                ...
            </>
        </>	
    </>
    this means whenever the test.do is requested, the bean called myController will handle the request.
    Code:
    <bean id="myController" class="org...MyController">
        <property name="formView"><value>login.jsp</value></property>
        ...
    </>
    let me know if this helps,
    Ryan

    Comment


    • #3
      Thanks, that does help.

      I had just sort of figured that out. I was confused because the one time the Spring documentation mentions it, they don't use a real value there. Also, the naming convention got me at first, since I was thinking class name (upper case first character), and it's following attribute name (lower case that converts to upper in set/get methods).

      Comment


      • #4
        YIKES!!!
        I had never actually looked at this tutorial and it seems like there are some problems:
        Code:
        String now = (new java.util.Date()).toString();
        logger.info("returning from PriceIncreaseForm view to " + getSuccessView();
        
        return new ModelAndView(new RedirectView(getSuccessView()));
        First of all, this won't even compile... but, you are correct that now is not used as it appears that the author was going to use it in the logger. If we wanted the now variable to be pushed out to the screen we would need to add a few things:

        add a now field to the command(bus.PriceIncrease) and implement getters/setters.
        edit the jsp to bind to the now field
        Code:
        <spring:bind path="priceIncrease.now">
            Now:<c:out value="${status.value}" /></span>
        </spring:bind>
        we would also have to set the now property on the command, which can be done in formbackingObject method or the onSubmit... if doing so in the onsubmit, you will need to make sure to pass the command to the next controller through session or the ModelAndView constructor.

        let me know if you have any more questions

        Comment


        • #5
          Actually, the code did compile.

          As for the code you suggested for the "now" attribute; I don't think it would cover what I want. The PriceIncrease object is bound to the priceincrease.jsp page. But, the example has the controller redirecting back to the hello.jsp (where now is already printed out... also, no form on the page).

          The controller for hello.jsp has a map, called myModel, where it stores a ProductManager object, and a version of "now". Is it possible to pass "now" from one controller to the next one?

          Maybe it would help if I could get a step by step list of what methods are being fired as the app goes through its pages.

          Comment


          • #6
            the best way I learned the method call hierarchy was to slap a debugger on to my app and attach the spring source.

            The way to pass data from one controller to the other is usually sending the data through session (I usually just build some of the command in the onSubmit method). Then, in my next controller's formbackingObject method, I get the command out of session and process it from there. As I said earlier, instead of dealing with the session... you can return a ModelAndView(String viewName, String modelName, Object modelObject) where you can insert the command... you can get the command back by calling getCommand (but I am not exactly sure about that so if anyone does, please correct me). The session way works fine for me.

            for a list of method calls, check out the API:
            http://www.springframework.org/docs/...ontroller.html

            Comment


            • #7
              Well, I'm making progress. I've added onto the MVC tutorial a page where you can add additional products. I have the complete list of products displaying on the formView page, so it submits and redirects to itself .

              It took me a while to figure out that a map passed in the ModelAndView (which shows up as GET parameters in the URL) isn't the same as the Map from referenceData.

              I have to admit I'm not crazy about the parameters showing up in the URL, and would rather send stuff via session. But I've noticed that neither of the two methods talked about when processing a form, doSubmitAction and onSubmit, take an HttpServletRequest... meaning they don't have access to a session. When procession a form, what method do I override to store stuff in the session?

              Comment


              • #8
                onSubmit() has several possible signatures, one of which does receive the HttpServletRequest as a parameter, so you can have access to the Session. Check out the JavaDoc.

                HTH

                Comment

                Working...
                X