Announcement Announcement Module
Collapse
No announcement yet.
doubt how to make master/detail form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • doubt how to make master/detail form

    I'm new with Roo and Spring MVC.

    I'm trying to make a form master/detail but it's not working. I like to know if someone could make a exemplo for me how to make this.

    Somethink like a Product has many SubProducts.

    Produto(name)
    SubProduto(product, name, quantity)

  • #2
    Originally posted by tiagojesus View Post
    I'm new with Roo and Spring MVC.

    I'm trying to make a form master/detail but it's not working. I like to know if someone could make a exemplo for me how to make this.

    Somethink like a Product has many SubProducts.

    Produto(name)
    SubProduto(product, name, quantity)
    the picture attached have the form that I like to build

    Comment


    • #3
      I there's an example called "Pizza" on the web, that allows u to add "topping types" to the pizza's...


      that would, in essence have the same type of functionality that you are looking for

      link is here, might be worth looking at:

      http://static.springsource.org/sprin...beginning.html

      Comment


      • #4
        I saw this example. But what i like to do is in the same form, i add the Product and its Subproduct.

        Comment


        • #5
          Hi guys. I almost did. The follow code is form update form of Produto.
          But when I click on save button, the subproduto is saved with out the produto reference.

          Some tips?
          Code:
          <?xml version="1.0" encoding="UTF-8" standalone="no"?>
          <div xmlns:c="http://java.sun.com/jsp/jstl/core"
          	xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields"
          	xmlns:form="urn:jsptagdir:/WEB-INF/tags/form"
          	xmlns:spring="http://www.springframework.org/tags"
          	xmlns:springform="http://www.springframework.org/tags/form"
          	xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
          
                 <jsp:output omit-xml-declaration="yes" /> 
                       <form:update id="fu:com.tiagojesus.testeroo.modelo.Produto" 
                                 modelAttribute="produto" 
                                 path="/produtoes" 
                                 z="rAv2wRgGKqyDoXnpNGBtwMkOCR4=">
          	<field:input field="nome"
          		id="c:com.tiagojesus.testeroo.modelo.Produto.nome" max="30"
          		z="OIb+Bj7UIZijN9iKJbAx8nkqjK0=" />
          	<field:simple field="subProdutos"
          		id="c:com.tiagojesus.testeroo.modelo.Produto.subProdutos"
          		messageCode="entity.reference.not.managed"
          		messageCodeAttribute="Produto" 
                           z="GkaTNadxlahtsbdO3FiCmBv0J68=" />
          
          	<c:forEach items="${produto.subProdutos}" var="subProduto"
          		varStatus="loopStatus">
          		<p>SubProduto ${loopStatus.index}: ${subProduto.nome} <br />
                  <springform:input path="subProdutos[${loopStatus.index}].nome"/>
                  
          		</p>
          	</c:forEach>
          </form:update></div>

          Comment


          • #6
            Can you post the code from your Controller?

            Comment


            • #7
              I'd be interested in seeing this code as well. It might help me in my task to show the equivalent of a list of SubProducts in a datagrid instead of a dropdown - on the same page as the Product.

              Comment


              • #8
                The example project

                The project that i`m trying to make the master/detail is attached.

                The steps I make is:

                1. Create the Produto
                2. Create 3 Subproduto
                3. than I try to update the Produto

                This moment, I only trying to save produtos with all its subprodutos.
                Last edited by tiagojesus; Jun 24th, 2010, 05:14 PM.

                Comment


                • #9
                  Change archive

                  Please, I make a mistake on the project. We need change the update page from produto for the follow.

                  Code:
                  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
                  <div xmlns:c="http://java.sun.com/jsp/jstl/core"
                  	xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields"
                  	xmlns:form="urn:jsptagdir:/WEB-INF/tags/form"
                  	xmlns:spring="http://www.springframework.org/tags"
                  	xmlns:springform="http://www.springframework.org/tags/form"
                  	xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"><jsp:output
                  	omit-xml-declaration="yes" /> <form:update
                  	id="fu:com.tiagojesus.testeroo.modelo.Produto" modelAttribute="produto"
                  	path="/produtoes" z="rAv2wRgGKqyDoXnpNGBtwMkOCR4=">
                  	<field:input field="nome"
                  		id="c:com.tiagojesus.testeroo.modelo.Produto.nome" max="30"
                  		z="OIb+Bj7UIZijN9iKJbAx8nkqjK0=" />
                  	<field:simple field="subProdutos"
                  		id="c:com.tiagojesus.testeroo.modelo.Produto.subProdutos"
                  		messageCode="entity.reference.not.managed"
                  		messageCodeAttribute="Produto" z="GkaTNadxlahtsbdO3FiCmBv0J68=" />
                  
                  	<c:forEach items="${produto.subProdutos}" var="subProduto"
                  		varStatus="loopStatus">
                  		<p>SubProduto ${loopStatus.index}: ${subProduto.nome} <br />
                  		<springform:input path="subProdutos[${loopStatus.index}].nome"/>q
                          <springform:hidden path="subProdutos[${loopStatus.index}].produto.id"/>
                  		</p>
                  	</c:forEach>
                  </form:update></div>

                  Comment


                  • #10
                    Did anyone ever get this to work?

                    I've been looking at doing something similar, and was playing a bit around with it, but didn't get it working the way I wanted.

                    Comment


                    • #11
                      I’ve done something like this. I think it’s necessary for a reasonable user experience – the user should be able to add child items to the parent on the same page. I wish Roo gave some support for this. But it doesn’t so I had to do it by hand.
                      First of all I changed the Sets of child objects to be Lists – as you have done – so that Spring can bind.
                      Then in the parent view I iterate over the List of children, using
                      Code:
                      path="children[${loopStatus.index}]…
                      remembering a hidden field for the id – also as you have done.
                      I render these in an HTML table. I allow the user to delete children with a javascript function that simply deletes the table row. Another javascript function adds a row to the end of the table for the user to add additional children. The new row of course needs to have the right fields in it. I use an invisible template row containing the fields and just copy its innerHTML to the new row, but with the field names containing the new index. The template row contains “ROW” which gets token-replaced. (This ensures the template row doesn’t actually get bound or cause a bind error). A javascript variable or hidden field keeps track of how many children there are, and this gets incremented when you add a row.
                      Code:
                      newRow.innerHTML = tbl.rows[0].innerHTML.replace(/ROW/g, "["+count+"]");
                      Now the controller needs to dynamically bind elements in the list. You could use Spring’s AutoPopulatingList, as described here: http://eggsylife.co.uk/2009/11/30/sp...ists-and-ajax/

                      But my object is coming out of JPA and the list may have been replaced by a Hibernate class. So I ensure the list is large enough and fill with empty child objects before Spring binds to it:
                      Code:
                          @InitBinder
                          public void initDataBinder(WebDataBinder binder, HttpServletRequest request) {
                      String val = request.getParameter("childMaxIdx");//the hidden field counter
                      Parent parent = (Parent)binder.getTarget();
                      	        		int numToAdd = maxChildIdx+1 - parent.getChildren().size();
                      	        		for (int i=0; i<numToAdd; i++) {
                      	        			Child child = new Child();
                      	        			child.setParent(parent);
                      	        			parent.getChildren().add(child);
                      	        		}
                      Spring automatically binds everything if I annotate my submit method param with @Valid and also the children attribute of the Parent class:
                      Code:
                      @Valid
                      Private List<Child> children = new ArrayList<Child>();
                      Then in the submit method I delete any children that are not present in the request before updating the parent in the persistence layer.

                      Comment

                      Working...
                      X