Announcement Announcement Module
Collapse
No announcement yet.
Html Input ID / Name issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Html Input ID / Name issue

    Hi All -

    Here is the little snippet from the html page. As you can see i'm binding the input text to the bean property using Spring MVC.

    The issue i'm running into is for the "firstName" field if I use "name" attribute instead of the "id" attribute Spring is able to bind the value. If I just specify the "id" attribute the value is never set.

    I want to use the id attribute so the code is compliant across browsers and I dont have to change the existing javascript. Is there any configuration to force Spring to use the id attribute to bind the values

    Code:
     <spring:bind path="mybean.firstName">
       <label>First Name</label><input type="text" maxlength="20" id="firstName" value="<c:out value="${status.value}"/>"/>
    </spring:bind>

  • #2
    Check out <form:input /> tag.

    Comment


    • #3
      Thanks for the reply. Unfortunately, I dont you use the spring tag libraries. Is that the only way to resolve this?

      Comment


      • #4
        I'm pretty sure thats the only way. Do understand that this is not a limitation of spring but just the way it works. Form values are passed based on the name attributes and not the id attributes.

        If I may ask, why don't you use the form taglib? It not only simplifies development but also keeps messy jsp code clean.

        Comment


        • #5
          If you don't want to use the form taglib you can simply provide both the id and name manually.

          Code:
          <spring:bind path="mybean.firstName">
             <label>First Name</label>
             <input type="text" maxlength="20" id="${status.expression}" name="${status.expression}" value="${status.value}"/>
          </spring:bind>

          Comment

          Working...
          X