Announcement Announcement Module
Collapse
No announcement yet.
Forms and Lists. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Forms and Lists.

    Hi ,
    Could the same page contain both a list and a form at the same time.
    E.g: If I have a page that contains a table that displays a list of customers.
    And I have a button on that page that adds new customer.
    When I click that button , I want a new row to be inserted in that table in which I could edit the new customer details.
    How could this happen ? How will the controller look like?
    Thanks in Advance.
    Sherihan.

  • #2
    I'm used to use SimpleFormController. Just put your list in the referenceData method:

    Code:
         protected Map referenceData(HttpServletRequest request)
             throws ServletException {
             Map model = new HashMap();
             model.put("categoriaList", categoriaManager.getCategorias(null));
             return model;
         }
    And in the view use it like you'd normally use when using the Controller interface.

    Comment


    • #3
      Hi gilbertoca,
      Thanks for your reply.
      But, I have one ,one question.

      Here is my form jsp:

      %@ include file="/taglibs.jsp"%>
      <html>
      <title>Add Invoice</title>

      <p>Please fill in the invoice details:</p>

      <form method="post" action="<c:url value="/editInvoice.html"/>">
      <spring:bind path="invoice.id">
      <input type="hidden" name="id" value="${status.value}"/>
      </spring:bind>

      <table>
      <tr>
      <td>Invoice-Number:</td>
      <td>
      <spring:bind path="invoice.invoiceNumber">
      <input type="text" name="invoiceNumber" value="${status.value}"/>
      </spring:bind>
      </td>
      </tr>

      <tr>
      <td>Customer:</td>
      <td>
      <select name="cutomersList">

      </select>
      </td>

      </tr>

      <tr>
      <td>Date:</td>
      <td>
      <spring:bind path="invoice.date">
      <input type="text" name="date" value="${status.value}"/>
      </spring:bind>
      </td>
      </tr>

      </table>

      <p><input type="submit" name="submit" value="Submit"/>
      </form>
      </html>

      Would you plz, tell me how could I fill the customerList dropdown list with the data that was retrieved in the referenceData method.

      Thanks.

      Comment


      • #4
        Data added by referenceData are "located" in the request and can be accessed using the very same key that you used in the map generated in referenceData. That is, in the case of
        map.put("customerList", ...)
        you can do a foreach on the variable ${customerList} in a jstl view page.
        HTH,

        Comment


        • #5
          No problem!

          Code:
          	<spring&#58;bind path="produto.cdCategoria">                  
          	  <select name="<c&#58;out value="$&#123;status.expression&#125;"/>" d="<c&#58;out value="$&#123;status.expression&#125;"/>">
                    <c&#58;if test="$&#123;produto.cdCategoria == null&#125;"><option value="<c&#58;out value="0"/>"><fmt&#58;message key="combobox.selecioneumvalor"/></option>
          					  </c&#58;if>
          					
          					  <c&#58;forEach var="categoria" items="$&#123;categorias&#125;">
          						<c&#58;if test="$&#123;produto.cdCategoria == categoria.cdCategoria&#125;">
          						  <option selected="<c&#58;out value="$&#123;produto.cdCategoria&#125;"/>" value="<c&#58;out value="$&#123;categoria.cdCategoria&#125;"/>"><c&#58;out value="$&#123;categoria.nomeCategoria&#125;"/></option>
          						</c&#58;if>
          						<c&#58;if test="$&#123;produto.cdCategoria != categoria.cdCategoria&#125;">
          						  <option value="<c&#58;out value="$&#123;categoria.cdCategoria&#125;"/>"><c&#58;out value="$&#123;categoria.nomeCategoria&#125;"/></option>
          						</c&#58;if>
          					  </c&#58;forEach>
          					</select>
          					<span class="fieldError"><c&#58;out value="$&#123;status.errorMessage&#125;"/></span>
          					</spring&#58;bind>

          Comment

          Working...
          X