How to Use Spring Form Tags

Viewpoint
Teradata Viewpoint is Teradata's strategic and innovative SOV (single operational view) for Teradata DB, Aster, and HDP Hadoop systems management and monitoring that enables Teradata's Unified Data Architecture (UDA).
Teradata Employee

How to Use Spring Form Tags

Created for Spring MVC framework, Spring form tags allow you to bind data to the backing object used by your portlet's controller object. This is especially useful for implementing preferences in a portlet, but they can be used anywhere a form is required. These are the same kind of tags discussed in the JSP and Tags page.

See the Spring Framework Web MVC section on form tags for examples:

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html#view-jsp-...

Using Spring Form Tags in a Portlet

In order for you to use Spring form tags in your portlet, you need to include the library in your portlet JSP:

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

The prefix 'form' will be used to precede the Spring form tag names. This is how the JSP page knows which tag library to use. See the code snippets below to see the 'form' prefix in use. Spring form tags are only valid when contained with the Spring Form tag:

<form:form>
...
</form:form>

Now that the form is defined, input fields can be added, as shown below. In this example, taken from the Spring reference, there are two input fields, one for a first name and the second for a last name.

<form:form>
<table>
<tr>
<td>First Name:</td>
<td><form:input path="firstName" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><form:input path="lastName" /></td>
</tr>
</table>
</form:form>

Again, the 'form' in '<form:input ...' is from the taglib prefix at the top of the JSP page. The path attribute in the input tag binds the data entered in the input field to a property in the data backing object of the controller used for the JSP.

The data backing object in this case would have both of these fields along with accessor methods defined as shown:

public class UserInfo
{
...
private String firstName;
private String lastName;
...
public String getFirstName()
{
return firstName;
}

public void setFirstName(String firstName)
{
this.firstName = firstName;
}

public String getLastName()
{
return lastName;
}

public void setLastName(String lastName)
{
this.lastName = lastName;
}
...
}

References

 See the Spring Form TLD reference for details on valid tag attributes:

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/spring-form.tld.htm...

Tags (3)