仅在显示特定的h:message时显示JSF元素 [英] Display JSF element only if specific h:message is being displayed

查看:140
本文介绍了仅在显示特定的h:message时显示JSF元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个输入的h:form,每个输入都有自己的h:message,我正在寻找一种仅在特定条件下显示(使用render或分配一些styleClass)其他元素的方式正在显示h:message(在未显示h:message时隐藏).

I have a h:form with several inputs and each of them got its own h:message and I'm looking for a way to show (using render or assigning some styleClass) some other element only when specific h:message is being shown (and hide when that h:message is not being displayed).

这是一个代码段

<li>
    <h:panelGroup id="current_password_wrapper">
        <p:password value="#{myBean.myCurrPass}" id="current_password" required="true"
            styleClass="required_field" />
    </h:panelGroup>
    <h:message for="current_password"/>
</li>
<li>
    <h:panelGroup id="new_password_wrapper">
        <p:password value="#{myBean.myNewPass}" id="new_password" required="true"/>
    </h:panelGroup>
    <h:message for="new_password"/>
    <h:commandLink value="my value"/>
</li>

我想仅在显示<h:message for="new_password"/>时使h:commandLink可见

到目前为止,我什么都找不到...

So far I couldn't find anything...

推荐答案

如果您的环境支持EL 2.2,则可以检查

If your environment supports EL 2.2, then you could check if FacesContext#getMessageList() isn't empty for the particular client ID.

<p:password binding="#{new_password}" ... />
<h:commandLink ... rendered="#{not empty facesContext.getMessageList(new_password.clientId)}" />

如果由于验证错误而显示该消息,那么您也可以只检查

If the message is being shown as result of a validation error, then you could also just check the UIInput#isValid() state of the component associated with the message.

<p:password binding="#{new_password}" ... />
<h:commandLink ... rendered="#{not new_password.valid}" />

请注意,手动将表情消息添加到上下文不会将输入组件标记为无效.因此,应该使用抛出ValidatorException的真实Validator,或者必须以编程方式进行显式的input.setValid(false)调用.

Note that manually adding a faces message to the context won't mark the input component invalid. Therefor either a true Validator should be used which throws a ValidatorException, or an explicit input.setValid(false) call has to be done programmatically.

这篇关于仅在显示特定的h:message时显示JSF元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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