Initial value to textarea field in form tld

强颜欢笑 提交于 2019-12-13 04:24:46

问题


I am using spring mvc and in my jsp page I have a form with textarea.

I want the textarea to be pre filled with some text (it is an edit feature for article).

I tried the following.

<form:textarea id="description" path="article.description" value="${article.description}" onKeyUp="validationmethod($(this));" onKeyDown="validationmethod($(this));" />

But my textarea is still empty..

the value="" attribute works perfectly fine for <form:input> but not for text area.

if i try to put it betweeen the tag then i get the warning "Form:textarea must not be empty".

Please help.


回答1:


There is no value property in textarea when form tags are used. Path property is used for data binding. For eg., just before rendering the view in which you are using this textarea, populate the model object with the data in your controller as:

    @RequestMapping(value="/prepareArticleForm")
    public ModelAndView prepareArticle(Model model) {
        Article article = new Article();
        article.setDescription("Your text");
        return new ModelAndView("articleView","article",article);
    }

In your articleView jsp:

    <form:form action="someAction" commandName="article" method="post">         
        TextArea Description: <form:textarea path="description" onKeyUp="validationmethod($(this));" onKeyDown="validationmethod($(this));"/>
    </form:form>


来源:https://stackoverflow.com/questions/23201229/initial-value-to-textarea-field-in-form-tld

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!