gpt4 book ai didi

jsf - JSF:检查=“id”/>
转载 作者:行者123 更新时间:2023-12-03 12:15:31 24 4
gpt4 key购买 nike

我有一个表单,其中需要在输入元素下方显示验证错误消息。需要通过在错误消息和输入文本周围显示错误气泡来突出显示该错误。

为此,我需要检查单个元素的h:messages是否存在。
我可以检查是否存在全局错误消息,如下所示

<h:panelGroup rendered="#{not empty facesContext.messages}"> 
</h:panelGroup>

如何检查特定的客户端ID(例如名字)是否相同。所以像
faceContent.messages("creditCardNo")

我目前有一个解决方案,就是创建一个自定义解析器,但想知道是否有更好的解决方案。

最佳答案

The error needs to be highlighted by showing an error bubble around the error message ...



只需将 <h:message>与样式类一起使用即可定义所需的样式。
<h:inputText id="foo" />
<h:message for="foo" styleClass="error" />


.error {
border: 1px solid red;
background: pink;
}

...and the input text.



只需检查 UIInput#isValid() 是否为 true即可。从JSF 2.0开始,当前组件可通过隐式EL变量 #{component}获得。
<h:inputText styleClass="#{!component.valid ? 'error' : 'none'}" />

关于检查是否有特定客户端ID的消息的实际问题,那么您可能会发现 this answer很有趣。但是我认为这不适用于您的特定情况。

更新:根据注释,您似乎想对包含组件而不是单个组件进行样式设置。在这种情况下,请执行以下操作:
<h:panelGroup styleClass="#{!foo.valid ? 'error' : 'none'}">
<h:inputText id="foo" binding="#{foo}" />
<h:message for="foo" />
</h:panelGroup>

关于jsf - JSF:检查=“id”/> <h:message是否存在的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4522609/

24 4 0

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