表格tld中textarea字段的初始值 [英] Initial value to textarea field in form tld

查看:188
本文介绍了表格tld中textarea字段的初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring mvc,在我的jsp页面中,我有一个带有textarea的表单.

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).

我尝试了以下方法.

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

但是我的文本区域仍然是空的..

But my textarea is still empty..

value=""属性对于<form:input>而言非常合适,但对于文本区域则无济于事.

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

如果我尝试将其放在标签之间,则会收到警告"Form:textarea不能为空".

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

请帮助.

推荐答案

使用表单标签时,textarea中没有value属性. Path属性用于数据绑定.例如,在渲染您正在使用该文本区域的视图之前,用控制器中的数据填充模型对象,如下所示:

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);
    }

在您的articleView jsp中:

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>

这篇关于表格tld中textarea字段的初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆