Bean验证和facelet中的2个表单

时间:2013-11-24 10:58:01

标签: jsf jsf-2 bean-validation

我在facelet中有2个表单,1.xhtml

<h:form>
    <h:inputText id="id1" value="#{mBean.pr}"/>
    <h:commandButton value="Submit" action="response"/>
</h:form>
<h:form>
    <h:commandButton value="myCB" action="response"/>
    <h:inputText id="id2" value="#{mBean.pr}"/>
</h:form>
pr注释的

@DecimalMin("5.00")字段。在这种情况下,id1id2包含大于或等于5.00的值就足够了。但请考虑以下facelet 2.xhtml

 <h:form>
        <h:inputText id="id1" value="#{hello.sur}"/>
        <h:inputText id="id2" value="#{hello.sur}"/>
        <h:commandButton value="Submit" action="response">
        </h:commandButton>
 </h:form>

在此,id1id2都必须包含大于5.00的值。

我不明白为什么会这样?

1 个答案:

答案 0 :(得分:1)

表单不起作用。当您提交某个表单时,只有表单中的输入 才能在模型中发送,处理,转换,验证和更新。表格是基于每个表格提交的,而不是基于每页的左右。页面可以具有多种形式,具有完全不同的职责,例如,登录表单和联系表单。当您提交登录表单时,处理联系表单的输入并在其上显示验证错误是没有意义的。

实际上,每个表单还应该有一个单独的请求/视图作用域支持bean。这不是技术要求,只是“良好的设计”要求。

相关问题