Announcement Announcement Module
Collapse
No announcement yet.
Help in a very Simple sample Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help in a very Simple sample

    Hello.

    I am a newby in Spring MVC. So sorry about any mistake and about the so basic question I'm searching help for :S. I installed all the framework following the step by step we can find at springframework.org site.

    It is a very silly hello.jsp, with list (furniture) controlled by a InventoryController, wich implements Controller, and a increaseprice.jsp, controlled by a PriceIncreaseFormController, wich extends from SimpleFormController, with a very simple form for increasing the price of all items in data base. Here you have both jsps:

    Code:
    <html>
      <head><title><fmt:message key="title"/></title></head>
      <body>
        <h1><fmt:message key="heading"/></h1>
        <p><fmt:message key="greeting"/> <c:out value="${model.now}"/></p>
        <h3>Products</h3>
        <c:forEach items="${model.products}" var="prod">
          <c:out value="${prod.description}"/> <i>$<c:out value="${prod.price}"/></i><br><br>
        </c:forEach>
        <br>
        <a href="<c:url value="priceincrease.htm"/>">Increase Prices</a>
        <br>
      </body>
    </html>
    Code:
    <html>
    <head>
      <title><fmt:message key="title"/></title>
      <style>
        .error { color: red; }
      </style>  
    </head>
    <body>
    <h1><fmt:message key="priceincrease.heading"/></h1>
    <form:form method="post" commandName="priceIncrease">
      <table width="95%" bgcolor="f8f8ff" border="0" cellspacing="0" cellpadding="5">
      <tr>
        <h3>Products</h3>
        <c:forEach items="${model.products}" var="prod">
          <c:out value="${prod.description}"/> <i>$<c:out value="${prod.price}"/></i><br><br>
        </c:forEach>
      </tr>
        <tr>
          <td align="right" width="20%">Increase (%):</td>
            <td width="20%">
              <form:input path="percentage"/>
            </td>
            <td width="60%">
              <form:errors path="percentage" cssClass="error"/>
            </td>
        </tr>
      </table>
      <br>
      <input type="submit" 
    </form:form>
    <a href="<c:url value="hello.htm"/>">Home</a>
    </body>
    </html>
    Everything works fine.

    Now I'm trying to improve a little its functionality. I want the list and the form in the same jsp. So something like this:

    Code:
    <form:form method="post" commandName="priceIncrease">
      <table width="95%" bgcolor="f8f8ff" border="0" cellspacing="0" cellpadding="5">
      <tr>
        <h3>Products</h3>
        <c:forEach items="${model.products}" var="prod">
          <c:out value="${prod.description}"/> <i>$<c:out value="${prod.price}"/></i><br><br>
        </c:forEach>
      </tr>
        <tr>
          <td align="right" width="20%">Increase (%):</td>
            <td width="20%">
              <form:input path="percentage"/>
            </td>
            <td width="60%">
              <form:errors path="percentage" cssClass="error"/>
            </td>
        </tr>
      </table>
      <br>
      <input type="submit" align="center" value="Increase" name="Increase">
    </form:form>
    Somehow I don't get this to show any product at the product list. Kind of I am not putting in the model the list of products I get from persistence.

    The question is: the controller of the view "priceincrease.htm" should be a SimpleFormController or a Controller or a MultiactionController or what?

    Now it is a SimpleFormController, but I don't get it how to request from persistence the product list before the jsp shows it up.

    Is there any method I could overwrite in SimpleFormController, that could execute before the view, so I can previously load the product list? I tried with HandleRequest, but I get all the time the following error:

    Code:
    Neither BindingResult nor plain target object for bean name 'priceIncrease' available as request attribute
    There you have the springapp-servlet.xml:

    Code:
        <bean name="/hello.htm" class="springapp.web.InventoryController">
            <property name="productManager" ref="productManager"/>
        </bean>
    
        <bean name="/priceincrease.htm" class="springapp.web.PriceIncreaseFormController">
            <property name="productManager" ref="productManager"/>
            <property name="sessionForm" value="true"/>
            <property name="commandName" value="priceIncrease"/>
            <property name="commandClass" value="springapp.service.PriceIncrease"/>
            <property name="validator">
                <bean class="springapp.service.PriceIncreaseValidator"/>
            </property>
            <property name="formView" value="priceincrease"/>
            <property name="successView" value="priceincrease.htm"/>
        </bean>
    
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
            <property name="prefix" value="/jsp/"></property>
            <property name="suffix" value=".jsp"></property>        
        </bean>
    As you can see... I really have a mess in my head :S. Some help, please.

    Thank you,

    Pedro
Working...
X