Initial value to textarea field in form tld

2019-09-19 04:36发布

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条回答
甜甜的少女心
2楼-- · 2019-09-19 04:53

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>
查看更多
登录 后发表回答