简体   繁体   English

JSF 2.0通过EL检查组件是否在复合组件内部有效

[英]JSF 2.0 checking by EL if components are valid inside composite component

there is an example what I want to achieve inside my JSF composite component: 在我的JSF复合组件中有一个示例要实现:

<h:inputText id="name" value="#{cc.attrs.value.name}" styleClass="#{(component.valid) ? 'required' : 'required invalid'}" validatorMessage="bad name" requiredMessage="name required" immediate="true" required="true">
    <f:validateRegex pattern="^[\p{L}' ]{2,19}$" />
    <f:ajax event="blur" execute="name" render="name testPanel" immediate="true"/>
</h:inputText>

<h:inputText id="surname" value="#{cc.attrs.value.surname}" styleClass="#{(component.valid) ? 'required' : 'required invalid'}" validatorMessage="bad surname" requiredMessage="surname required" immediate="true" required="true">
    <f:validateRegex pattern="^[\p{L}' ]{2,19}$" />
    <f:ajax event="blur" execute="name" render="surname testPanel" immediate="true"/>
</h:inputText>

<h:panelGroup id="testPanel" styleClass="#{(!name.valid || !surname.valid) ? 'warning' : 'none'}">
    <h:message id="msgName" for="name" showSummary="true" showDetail="false" />
    <h:message id="msgSurname" for="surname" showSummary="true" showDetail="false" />
</h:panelGroup>

The problem is how to evaluate if name or surname are valid/invalid at the 'testPanel'. 问题是如何在“ testPanel”上评估名称或姓氏是否有效/无效。 I want both messages 'msgName' and 'msgSurname' to be wrapped with styled span (html output) that would be not present if there are no error messages for 'name' or 'surname'. 我希望消息“ msgName”和“ msgSurname”都用样式化的跨度(HTML输出)包装,如果没有“名称”或“姓氏”的错误消息,则不会出现。

Any help appreciated :) 任何帮助表示赞赏:)

Bind the components to the EL scope using binding attribute: 使用binding属性将组件绑定到EL作用域:

<h:inputText binding="#{name}" ... />
<h:inputText binding="#{surname}" ... />

This way your EL attempt in the styleClass attribute will work. 这样,您的EL在styleClass属性中的尝试将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM