Announcement Announcement Module
Collapse
No announcement yet.
Passing values between forms? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing values between forms?

    Hi,

    I'm new to MVC web programming (I'm mostly used to working with BL objects and server-side stuff) and my Web UI experience is just on php/perl and some perl templates, also a little jsp but very messy (almost no separation whatsoever of logic and presentation ).

    So I have this situation: I'm working on a tree-like structure that can be navigated with a web interface, using one page per node. This page has all the information on the current node and links to "create new node" on the current one (let's call the current node Node A). This node browser is a form/controller and every link to other nodes calls this with the target node's id.

    The "new node link" goes to a form that requires the user's input to get the information needed for a new node. My problem is that I need to get Node A's id in this page, because if I don't the controller won't know how to link the newly created node to Node A.

    Currently I solved this using a form submission in the "browse node" view jsp that calls the "new Node" jsp form view with an incomplete New Node command object with just the id, and the new node controller checks for this and uses it to display either the new node form or the new node success view. That way I get the parent node ID in the form. The problem I see with this approach is that I have a hardcoded link (i.e. href="newNode.htm") to the new node form in the browse list view. I feel that this is probably not the "best practices" way since I have a hardcoded url instead of a command name (using the new node command clashes since it's already a form for another command).

    So, what's the properly MVC-ish way of passing this information between separate forms?

    Thanks in advance.

  • #2
    Why can't you just pass a parameter to the Controller which creates a new node, i.e. createNode.htm?parentId=4

    Comment


    • #3
      Originally posted by leetgeezer View Post
      Why can't you just pass a parameter to the Controller which creates a new node, i.e. createNode.htm?parentId=4
      That's what I'm doing (although using POST and a hidden input instead of GET) - however, to do that I have to hardcode the "createNode.htm" in the original page. Since SpringMVC is so much about uncoupling and parametrization I was wondering if there was a better way to do it.

      Thanks for your reply.

      Comment


      • #4
        Originally posted by sotua View Post
        The "new node link" goes to a form that requires the user's input to get the information needed for a new node. My problem is that I need to get Node A's id in this page, because if I don't the controller won't know how to link the newly created node to Node A.
        When I read this I thought you need bindOnNewForm set to true on the controller, but ...

        Originally posted by sotua View Post
        Currently I solved this using a form submission in the "browse node" view jsp that calls the "new Node" jsp form view with an incomplete New Node command object with just the id, and the new node controller checks for this and uses it to display either the new node form or the new node success view. That way I get the parent node ID in the form. The problem I see with this approach is that I have a hardcoded link (i.e. href="newNode.htm") to the new node form in the browse list view. I feel that this is probably not the "best practices" way since I have a hardcoded url instead of a command name (using the new node command clashes since it's already a form for another command).
        That part confused me completely

        Jörg

        Comment


        • #5
          Well, I use freemarker macro for links generation like this:

          Code:
          <@mylib.a page="SHOW_EMPLOYEE" params="id=3" attributes='class="link"'/>
          Show Employee
          </@mylib.a>
          Recently I have asked a question about link management but nobody answered.
          Have you found a better way so far?

          Comment


          • #6
            Originally posted by Jörg Heinicke View Post
            When I read this I thought you need bindOnNewForm set to true on the controller, but ...

            That part confused me completely

            Jörg


            Let me try again:

            I need to know the Node Id when I try to create a new node.

            My current solution is something like this:

            Code:
            <form method="POST" action="newNode.htm">
            <input type="hidden" name="parentNodeId" value="${currentNode.id}">
            <input type="submit" value="Create New Node Here"/>
            </form>
            However, that doesn't look particularly clean, since I had to embed a hardcoded "newNode.htm" reference. I was wondering if there's a better way to reference the newNode form. For example, if someone decides that "htm" doesn't look good and changes the configuration of the view resolver to point to .form or .whatever, my "create new node here" buttons will no longer work.

            Thanks for your answer.

            Comment


            • #7
              You somehow need to pass both details: 1. You want to create a new node. 2. Parent node is node A. How you do pass those information is up to you. There are countless articles on the web how to create good URLs.

              I wonder how a framework can overtake this task - except by knowing all links and forms in advance and creating special ids for them. That sounds very much like a state machine where it knows the current state and the possible paths to the next states. No idea if Spring web flow goes into that direction.

              Jörg

              Comment


              • #8
                Originally posted by Jörg Heinicke View Post
                You somehow need to pass both details: 1. You want to create a new node. 2. Parent node is node A. How you do pass those information is up to you. There are countless articles on the web how to create good URLs.
                Jörg
                I'd be glad if you recommended any good article on this. I've been looking and I haven't found anything interesting :/

                Comment


                • #9
                  Originally posted by leetgeezer View Post
                  I'd be glad if you recommended any good article on this.
                  THE article on that subject is "Cool URIs don't change". Also Jakob Nielsen, a usability guy/guru, has probably not only this one article "URL as UI". Another link a short Google tour revealed: "URLS! URLS! URLS!".

                  Jörg

                  Comment


                  • #10
                    Great! Huge thanks. Now I'll get back to my reading

                    Comment

                    Working...
                    X