仅在显示特定的h:message时显示JSF元素 [英] Display JSF element only if specific h:message is being displayed
问题描述
我有一个带有多个输入的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...
推荐答案
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屋!