我的问题是,我在一个 JSF 页面中有 2 个表单,每个表单都有其<h:message>
or <h:messages>
标签。正如我们所知,消息/消息标签会打印任何验证错误,所以会发生的情况是,假设我将两个表单中任何一个的字段留空,它应该打印“字段不能留空”或某种消息。它给出了这个消息,但它给出了两次,因为有两种形式。因此,我在两种表单中都看到相同的错误/验证消息。
所以我需要的是<h:messages>
or the <h:message>
标签应该只为各自的表单显示一次错误/验证消息!
因此,任何帮助将不胜感激!
如果您使用 JSF 2,那么您只需通过 ajax 提交和更新表单即可。这允许部分更新视图。
<h:form>
<h:messages />
...
<h:commandButton ...>
<f:ajax execute="@form" render="@form" />
</h:commandButton>
</h:form>
<h:form>
<h:messages />
...
<h:commandButton ...>
<f:ajax execute="@form" render="@form" />
</h:commandButton>
</h:form>
或者,如果由于某些不明显的原因您不能/不想使用 ajax,或者仍在使用旧版 JSF 1.x,请签入rendered
的属性<h:messages>
如果所需的形式是已提交 or not.
<h:form binding="#{form1}">
<h:messages rendered="#{form1.submitted}" />
...
<h:commandButton ... />
</h:form>
<h:form binding="#{form2}">
<h:messages rendered="#{form2.submitted}" />
...
<h:commandButton ... />
</h:form>
The <h:message>
顺便说一句,不应该有这个问题,与您在问题中暗示的相反。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)