Announcement Announcement Module
Collapse
No announcement yet.
<Form:checkbox> tag issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <Form:checkbox> tag issue

    Hey guys,

    I have the following order.jsp file and am trying to use the <form:checkbox> tag to build a bind path to a command object orderInfo which contains a variable bread. However when I add the following line of code to my .jsp file;

    Code:
    <form:checkbox path="orderInfo.bread"/>
    i get the following error

    org.apache.jasper.JasperException: Exception in JSP: /WEB-INF/jsp/order.jsp:19

    16: <tr>
    17: <td width="235">Bread:</td>
    18: <td width="353">
    19: <form:checkbox path="orderInfo.bread"/>
    20: </td>
    21: </tr>
    22: <tr>
    I have checked the appropriate documentation

    http://static.springframework.org/sp...rence/mvc.html

    and the tags are used correctly. So I don't understand what it could be. Can anyone help?

    Full listing of the orderInfo class and the order.jsp are below.

    Code:
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <a href="<core:url value="main.htm"/>">testing</a>
    
    <form:form commandName="orderInfo">
      <table width="604" border="1">
        <tr>
          <td width="235">Bread:</td>
          <td width="353">
                 <form:checkbox path="orderInfo.bread"/>
          </td>
        </tr>
        <tr>
          <td>Meat:</td>
          <td>
              <form:input path="meat" size="9" maxlength="9" />          
    
           </td>
        </tr>
        <tr>
          <td>Veg: </td>
          <td>
              <form:input path="veg" size="3" maxlength="3" />
          </td>        
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="Submit" value="Submit" /></td>
        </tr>
      </table>
    </form:form>
    </body>
    </html>
    Code:
    package bus;
    
    public class OrderInfo {
        
        private String meat;
        
        private String veg;
    
        
        private boolean bread;
        
        public boolean isBread() {
            return bread;
        }
    
        public void setBread(boolean bread) {
            this.bread = bread;
        }
        
    
        public String getMeat() {
            return meat;
        }
    
        public void setMeat(String meat) {
            this.meat = meat;
        }
    
        public String getVeg() {
            return veg;
        }
    
        public void setVeg(String veg) {
            this.veg = veg;
        }
    
     
    
    }

  • #2
    [quote]the tags are used correctly[/code]
    No they aren't. When using the form:* tags you musn't include the name of the command Object in your path (as opposed to the spring:bind tags). So ommit the orderInfo. and it should work.

    If you check the sample application regarding the spring flow tags and read the refence guide chapter about them it should be clear.

    Comment


    • #3
      [QUOTE=mdeinum;96278]
      the tags are used correctly[/code]
      No they aren't. When using the form:* tags you musn't include the name of the command Object in your path (as opposed to the spring:bind tags). So ommit the orderInfo. and it should work.

      If you check the sample application regarding the spring flow tags and read the refence guide chapter about them it should be clear.
      Yes it works perfect thank you. However, there is still something confusing me. The form tag in the example program showing the <form:checkbox> tag in use does not have the name of the command object specified and also the name of the path is included. As follows;

      Code:
      <form:form>
          <table>
              <tr>
                  <td>Subscribe to newsletter?:</td>
                  <%-- Approach 1: Property is of type java.lang.Boolean --%>
                  <td><form:checkbox path="preferences.receiveNewsletter"/></td>
                  <td></td>
              </tr>
      why is the path to the command object included here? Because the command command object name has not been specified? If this is so, then why did this not work for me?

      Comment


      • #4
        The default commandObject name is command this default is also used by the form tags. So basically preferences.receiveNewsletter translates to command.preferences.receiveNewsletter.

        Where preferences is a property of the command object and receiveNewsletter a property of preferences. If you would check the source of the controller you would see that a User object is the command object. User has a property named preferences which is a Preferences object. The Preferences object has a boolean property named receiveNewsletter.

        The form tag in the example program showing the <form:checkbox> tag in use does not have the name of the command object specified and also the name of the path is included.
        The link I provided in my earlier post explains it clearly in the third example (13.9.2). The preferences part is there because it is a so called nested property.
        Last edited by Marten Deinum; Jan 17th, 2007, 05:47 AM. Reason: Added some links to documentation.

        Comment

        Working...
        X