我们如何使用多个< h:messages>标签或< h:message>单个JSF页面中的标签? [英] How can we use multiple <h:messages> tags or <h:message> tags in a single JSF page?

查看:111
本文介绍了我们如何使用多个< h:messages>标签或< h:message>单个JSF页面中的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My problem is that I have 2 forms in a single JSF page each having its <h:message> or <h:messages> tag. As we know the message/messages tags print any validation errors, so what happens is, suppose I leave the fields of any of the 2 forms empty it should print "Fields cannot be left blank" or some kind of message. It gives this message, but it gives twice as there are two forms. So I see the same error/validation message at each of the two forms.

所以我需要的是<h:messages><h:message>标记对于它们各自的每种形式应该只显示一次错误/验证消息!

So what I need is the <h:messages> or the <h:message> tag should display error/validation message only once for each of their respective forms!!

因此,我们将不胜感激!

So any help would greatly be appreciated!!

推荐答案

如果您使用的是JSF 2,则可以通过ajax提交并更新表单.这样可以部分更新视图.

If you're using JSF 2, then you could just submit and update the form by ajax. This allows for partially updating the 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,那么请检查<h:messages>rendered属性,如果所需的形式是已提交或不是.

Or if you can't/don't want to use ajax for some unobvious reason, or are still using the legacy JSF 1.x, then check in the rendered attribute of <h:messages> if the desired form is been submitted 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>

与您在问题中暗示的相反,<h:message>不应出现此问题.

The <h:message> shouldn't have this problem by the way, in contrary to what you're implying in your question.

这篇关于我们如何使用多个&lt; h:messages&gt;标签或&lt; h:message&gt;单个JSF页面中的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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