jsp - spring mvc: How Can I give the <form:textarea /> tag a default value? -


i learning form processing spring mvc framework. have problem giving <form:textarea /> tag default value.
when created .jsp file follow,

<form:textarea path="content" id="my-text-box" />${content} 

jsp parser translate above line to: (let me assume ${content} contains "hello world".)

<textarea id="my-text-box" name="content"></textarea>third hello world! 

also, giving value attribute not work.

<form:textarea value="${content}" path="content" id="my-text-box" /> 

jsp gives me html output:

<textarea id="my-text-box" name="content" value="third hello world!"></textarea> 

you know <textarea> tag not have value attribute.

how can pass default value <form:textarea> tag? thank in advance.

the spring form tags data binding (e.g. model attributes bind form via path attribute of form). if need specify defaults, set content attribute of modelyouarepassingtoview desired default value in controller before gets view.

if using spring mvc , @requestmapping, place in controller @modelattribute method. example:

@modelattribute("modelyouarepassingtoview") public modelyouarepassingtoview createdefault() {    //construct default values "content"     //attribute, , show in textarea after bindind    modelyouarepassingtoview myapv = new modelyouarepassingtoview();     myapv.setcontent(..); //default value    return myapv; } 

in form, make sure include modelattribute tag attribute:

<form:form modelattribute="modelyouarepassingtoview" ...>   <form:textarea path="content" ..>  

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -