Jaanus
Jaanus

Reputation: 16541

Java Spring form tag question

I am using JSPs, and this is my contacts.jsp

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
    <title>Spring 3.0 MVC series: Contact manager</title>
</head>
<body>
<h2>Contact Manager</h2>
<form:form method="post" action="addContact.html">

    <table>
        <tr>
            <td><form:label path="firstName">First Name</form:label></td> // LABEL
            <td><form:input path="firstName" /></td>
        </tr>
        <tr>
            <td><form:label path="lastName">Last Name</form:label></td>
            <td><form:input path="lastName" /></td>
        </tr>
        <tr>
            <td><form:label path="lastName">Email</form:label></td>
            <td><form:input path="email" /></td>
        </tr>
        <tr>
            <td><form:label path="lastName">Telephone</form:label></td>
            <td><form:input path="telephone" /></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="Add Contact"/>
            </td>
        </tr>
    </table>  

</form:form>
</body>
</html>

My questions is, that when i change form:label path="firstName" into form:label path="firstname", why tomcat starts throwing errors? Doesn't the model only need the input path, since the value inside input path, is the value it will use?

EDIT:

should i even use the form:label tag , why is it used?

Upvotes: 3

Views: 10965

Answers (1)

Jeremy
Jeremy

Reputation: 22415

It's because firstName is either used literally, or is translated into the method getFirstName().

Either way, the capitalization matters when the lookup is performed.


For your question on whether or not you need the path in the label: If you provide the path, then the label will know which input it belongs to. In HTML, that allows you to click on the label and have the input field gain focus. I assume the output HTML for your code is something like this:

<tr>
  <td><label for="firstName"></td>
  <td><input type="text" id="firstName"></td>
</tr>

Upvotes: 9

Related Questions