如何将默认值传递给Spring输入/隐藏元素?

时间:2013-03-02 15:49:50

标签: spring spring-mvc

假设我有以下Spring表单

<form:form id="mainForm" name="mainForm" 
           method="post" action="Temp.htm" commandName="tempBean">

    <form:hidden path="stringValue" />

</form:form>

隐藏字段使用命令bean映射 - TempBean。如果,我需要传递一个对这个隐藏字段是动态的默认值并依赖于其他一些操作呢?


HTML上下文:

<c:set var="someVariable" value="${someValue}"/>

<input type="hidden" 
       id="stringValue" 
       name="stringValue" 
       value="${someVariable}"/>

<form:input><form:hidden>等标记没有value属性。那么,在这种情况下如何将默认值传递给命令对象?

我正在使用Spring 3.2.0。

1 个答案:

答案 0 :(得分:0)

您可以使用通用名称

为您使用的bean设置默认值
@RequestMapping(value="/someView.html", method=RequestMethod.GET)
    public String someView(ModelMap modelMap){

        TempBean tempBean = new TempBean();
                tempBean.setStringValue(somevalue);
        modelMap.addAttribute(tempBean );
        return "something";
    }