Results 1 to 3 of 3

Thread: What is wrong with my bind tags ?

  1. #1
    Join Date
    May 2005
    Location
    Boston, MA
    Posts
    17

    Default What is wrong with my bind tags ?

    Here is my JSP code:


    <%@ page session="false"%>

    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

    <html>

    <head>
    <title>Example Application</title>
    </head>

    <body topmargin="0" leftmargin="0">

    <table align="center" cellpadding="50">
    <tr>
    <td>
    <form method="post">
    <table align="center" cellspacing="1" cellpadding="0">
    <tr>
    <th align="center">Person</th>
    </tr>
    <tr>
    <td>
    <table width="100%" cellpadding="5">
    <tr>
    <td align="right"><b></b>First Name:</td>
    <td>
    <spring:bind path="command.firstName">
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" maxlength="50" size="50" />
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td align="right"><b></b>Last Name:</td>
    <td>
    <spring:bind path="command.lastName">
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" maxlength="50" size="50" />
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td align="center" colspan="2">
    <input type="submit" value="Save" />
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>

    </body>
    </html>



    Here is my Controller code:


    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
    Object command, BindException errors) throws Exception {

    if (log.isDebugEnabled()) {
    log.debug("Entered onSubmit");
    log.debug("Parameters:");
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements(); ) {
    String element = (String) e.nextElement();
    log.debug(element + "=" + request.getParameter(element));
    }
    }

    Person person1 = (Person) command;

    if (log.isDebugEnabled()) {
    log.debug("Person from command: " + person1);
    }

    Person person2 = (Person) getCommand(request);

    if (log.isDebugEnabled()) {
    log.debug("Person from getCommand(): " + person2);
    }

    Person person3 = (Person) formBackingObject(request);

    if (log.isDebugEnabled()) {
    log.debug("Person from formBackingObject(): " + person3);
    }

    getExample().changePerson(person1);

    // Display the Persons with the new additions
    return new ModelAndView("personsView", "persons", getExample().getPersons());
    }


    On Submit, my log looks like this:
    DEBUG PersonChangeController - Entered onSubmit
    DEBUG PersonChangeController - Parameters:
    DEBUG PersonChangeController - lastName=Simpson
    DEBUG PersonChangeController - key=3
    DEBUG PersonChangeController - firstName=Homer
    DEBUG PersonChangeController - Person from command: 3 'Homer ,Homer' 'Simpson ,x'
    DEBUG PersonChangeController - Person from getCommand(): 0 'null' 'null'
    DEBUG PersonChangeController - Person from formBackingObject(): 0 'null' 'null'

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    What is wrong with my bind tags ?
    What's the problem - the parameters are bound to the command object passed in by onSubmit.
    From the javadoc for getCommand() and formBackingObject(), "Note that the form object gets removed from the session".

  3. #3
    Join Date
    May 2005
    Location
    Boston, MA
    Posts
    17

    Default

    That's not my problem. I just added the getCommand() and formBackingObject() log messages trying to figure out where I was going wrong. The real issue I have is when I change the form values and submit. If I change the Person's name from Homer Simpson to Ned Flanders, I get the old AND new values in the command object separated by commas:

    DEBUG PersonChangeController - Person from command: 3 'Homer,Ned' 'Simpson,Flanders'

    I'm pretty much following the PetClinic sample application. Our previous app server (WAS 4.0) didn't support the Spring bind tags, so I was forced to bind the form fields manually. We upgraded (to WAS 6.0) and I wanted to convert to the Spring bind tags.

Similar Threads

  1. Replies: 1
    Last Post: Sep 9th, 2005, 03:49 AM
  2. Replies: 8
    Last Post: Jul 29th, 2005, 06:40 PM
  3. Newbie bind question: bind an entire form?
    By kendelong in forum Web
    Replies: 0
    Last Post: Feb 4th, 2005, 04:02 PM
  4. Replies: 3
    Last Post: Nov 25th, 2004, 01:42 PM
  5. Replies: 2
    Last Post: Sep 23rd, 2004, 11:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •