Domanda

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.

È stato utile?

Soluzione

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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top