Announcement Announcement Module
Collapse
No announcement yet.
Passing request parms thru "new ModelAndView()" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing request parms thru "new ModelAndView()"

    i have a function that returns as such....

    return new ModelAndView("/queueManagement/queueManagementHomepage", "queueCmd", queue);

    i need to be able to pass request parameters, but when correctly(!) appended to "/queueManagement/queueManagementHomepage" i get a 404 "URL Not Found". turns out when i run this app w/o my changes, the *real* URL it goes to is "/queueManagement.htm" (i'm guessing that there's some magic in "ModelAndView" that is translating this.)

    i then tried the following

    #1) return new ModelAndView("/queueManagement.htm?x=y&z=a", "queueCmd", queue);

    and

    #2) return new ModelAndView(new RedirectView("/queueManagement.htm?x=y&z=a", true), "queueCmd", queue);

    for #1 i got an invalid URL and #2 appeared to be looping thru the calling controller (was it calling itself??)

    can someone help a quasi-newby and tell me how this is *supposed* to happen????

    thanks in advance

  • #2
    Sounds like you're confusing request and view.

    A request comes in and gets mapped to a controller. The controller does some stuff and creates a model. The model is data that is exposed to the view. The view is the entity that renders the page. The physical file for the view (typically a JSP) can be named something very different from the request.

    Maybe the parameters you're tacking on the end should be included in the model?:

    Code:
    ModelAndView mav = new ModelAndView("/queueManagement/queueManagementHomepage", "queueCmd", queue);
    mav.addObject("x","y");
    mav.addObject("z","a");
    return mav;
    It really helps to understand the pipeline from request to view and it's definitely not immediately obvious when you're a newbie.

    RequestMappings determine what controller to use from a given request.
    ViewResolvers determine what JSP file to use from a given logical view. When you create the ModelAndView object, you're specifying the logical view.

    I hope I've understood where you're going wrong and have helped a bit.

    PUK

    Comment


    • #3
      That's great information!

      i take it that "mav.addObject("x","y")" puts "x" in the, uh, form (is the correct wording "Model"?) for the JSP s.t. in the JSP i can do something like

      <c:if test={x == "y"}>
      ...some html...
      </c:if>

      Comment


      • #4
        Originally posted by NovaDavidM View Post
        i take it that "mav.addObject("x","y")" puts "x" in the, uh, form (is the correct wording "Model"?)
        Yes, that's right. "puts x in the model" is correct.

        <c:if test={x == "y"}>
        ...some html...
        </c:if>
        You got the gist of it. There'd be quotes around the attribute value and a dollar sign before the opening brace and possibly some escaping of the quotes for "y". My JSP isn't that hot!

        PUK

        Comment

        Working...
        X