gpt4 book ai didi

jsf - 我们如何使用多个 tags or tags in a single JSF page?

转载 作者:行者123 更新时间:2023-12-04 05:27:04 25 4
gpt4 key购买 nike

我的问题是我在一个 JSF 页面中有 2 个表单,每个表单都有它的 <h:message><h:messages>标记。正如我们所知,消息/消息标签会打印任何验证错误,所以发生的情况是,假设我将 2 个表单中的任何一个的字段留空,它应该打印“字段不能留空”或某种消息。它给出了这个信息,但它给出了两次,因为有两种形式。所以我在两种表单中看到相同的错误/验证消息。

所以我需要的是<h:messages><h:message>标签应该只为它们各自的表单显示一次错误/验证消息!!

所以任何帮助将不胜感激!

最佳答案

如果您使用的是 JSF 2,那么您可以通过 ajax 提交和更新表单。这允许部分更新 View 。

<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> 的属性如果所需的表格是 submitted与否。
<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>
<h:message>顺便说一下,不应该有这个问题,这与您在问题中暗示的相反。

关于jsf - 我们如何使用多个 <h :messages> tags or <h:message> tags in a single JSF page?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13082911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com