0
votes

I want to get the value in a spring form based textarea using the jstl tag, like the code given below

How could I render this?

<form:textarea value="${u.content}" path="content">
</form:textarea>

I get the error "tag form:textarea must be empty, but is not" on running this view page

1

1 Answers

4
votes

If your form is bound to a commandName/modelAttribute you don't need the value attribute just the path is enough. e.g.

if form is declared like below.

<form:form id="form" method="post" modelAttribute="formBean">

your text area needs to be just

<form:textarea  path="name"/>

where name is an attribute of formBean object

public class FormBean {     
    private String name = "name";
}

Pre Initialized values.

@RequestMapping(value="/personForm")
public String showForm(Model model) {
    //read values from db and add it as model .e.g. 
    Person person = new Person();
    model.addAttribute("person", person);
    return "personForm";
}

jsp:

<form:form action="/personForm" commandName="person" method="post">         
   Name1: <form:textarea path="name"/>
</form:form>