I have a problem with giving the
tag a default value.
When I created a .jsp file as follow,
I faced a similar situation. The below code:
<form:textarea path="Content" id="my-text-box">${content}</form:textarea>
Worked out for me.
This works in Spring 4 where the form:textarea tag must be empty:
<form:textarea path="content" value="${Object.content}"/>
You can use jquery to get the model attribute value and set the value in textarea
$( function() {
var example = parseInt('${example}');
$("#bot").val(example);
} );
Maybe you can use placeholder.
<form:textarea
id="id"
class="class"
path="path"
placeholder="test"/>
You can also set the defaul text in the Model as well. Your jsp would have:
<form:textarea path="my-text-box" rows="20" cols="100" cssClass="rounded"/>
and then in the Model, you'd have:
private static final String DEFAULT_textareacontent = "Hello World";
private String my-text-box = DEFAULT_textareacontent;
Not sure if this is a best practice or not, but it seems to work for me.
You have to use JS along with Spring MVC to make this work. This is what I did:
Change your textarea to basic html as below:
<textarea id="myTextArea" onchange="here();">${content}</textarea>
OR
<textarea id="myTextArea" onchange="here();">third hello world!</textarea>
Add a hidden input field, using spring mvc:
<form:input type="hidden" id="content" path="Content" value="third hello world!"/>
Add the following JavaScript:
<script>
var text1 = document.getElementById('myTextArea').value;
function here() {
text1 = document.getElementById('myTextArea').value;
document.getElementById("content").value = text1;
}
</script>