我有两个h:selectManyCheckBox
,其必需属性设置为 true 。
我想要的是两个组件的必需属性协同工作。
仅在所选项目列表为空时,仅显示错误消息 。
现在我的问题是,如果其中任何一个为空,则会显示该消息。这是我的代码:
<rich:panel>
<f:facet name="header">
<h:outputText value="Actualización de catálogos"/>
</f:facet>
<h:panelGrid columns="4">
<h:outputLabel for="actualizarCatalogoPEC"
value="Actualizar catálogos PEC"/>
<h:selectBooleanCheckbox id="actualizarCatalogoPEC"
value="#{administrationBean.actualizaTodosPecChecked}">
<f:ajax event="click"
render="todosCatalogosPEC"/>
</h:selectBooleanCheckbox>
<h:outputLabel for="actualizarCatalogoSAGARPA"
value="Actualizar catálogos SAGARPA"/>
<h:selectBooleanCheckbox id="actualizarCatalogoSAGARPA"
value="#{administrationBean.actualizaTodosSagarpaChecked}">
<f:ajax event="click"
render="todosCatalogosSAGARPA"/>
</h:selectBooleanCheckbox>
<a4j:outputPanel id="todosCatalogosPEC">
<h:selectManyCheckbox id="selectCatalogosPEC"
disabled="#{administrationBean.actualizaTodosPecChecked}"
required="true"
value="#{administrationBean.catalogosPecSeleccionados}"
requiredMessage="Seleccione al menos un catálogo"
layout="pageDirection">
<f:selectItems value="#{administrationBean.catalogosPecOptions}"/>
</h:selectManyCheckbox>
</a4j:outputPanel>
<h:panelGroup/>
<a4j:outputPanel id="todosCatalogosSAGARPA">
<h:selectManyCheckbox id="selectCatalogosSAGARPA"
disabled="#{administrationBean.actualizaTodosSagarpaChecked}"
required="true"
value="#{administrationBean.catalogosSagarpaSeleccionados}"
requiredMessage="Seleccione al menos un catálogo"
layout="pageDirection" >
<f:selectItems value="#{administrationBean.catalogosSagarpaOptions}"/>
</h:selectManyCheckbox>
</a4j:outputPanel>
<h:panelGroup/>
<rich:message id="messageCatalogosPEC"
for="selectCatalogosPEC"/>
<h:panelGroup/>
<rich:message id="messageCatalogosSAGARPA"
for="selectCatalogosSAGARPA"/>
<h:panelGroup/>
<a4j:commandButton value="Actualizar catálogos"
render="messageCatalogosPEC"
action="#{administrationBean.doActualizaCatalogos}"/>
</h:panelGrid>
</rich:panel>
干杯
更新
我已将代码更改为:(刚刚添加了binding
并修改了required
)
<a4j:outputPanel id="todosCatalogosPEC">
<h:selectManyCheckbox id="selectCatalogosPEC"
disabled="#{administrationBean.actualizaTodosPecChecked}"
binding="selectCatalogosPEC"
required="#{empty selectCatalogosSAGARPA.value}"
value="#{administrationBean.catalogosPecSeleccionados}"
requiredMessage="Seleccione al menos un catálogo"
layout="pageDirection">
<f:selectItems value="#{administrationBean.catalogosPecOptions}"/>
</h:selectManyCheckbox>
</a4j:outputPanel>
<h:panelGroup/>
<a4j:outputPanel id="todosCatalogosSAGARPA">
<h:selectManyCheckbox id="selectCatalogosSAGARPA"
binding="selectCatalogosSAGARPA"
disabled="#{administrationBean.actualizaTodosSagarpaChecked}"
required="#{empty selectCatalogosPEC.value}"
value="#{administrationBean.catalogosSagarpaSeleccionados}"
requiredMessage="Seleccione al menos un catálogo"
layout="pageDirection" >
<f:selectItems value="#{administrationBean.catalogosSagarpaOptions}"/>
</h:selectManyCheckbox>
</a4j:outputPanel>
但得到了这个错误:
jun 01, 2012 10:31:37 AM org.apache.catalina.core.StandardWrapperValve invoke
Grave: Servlet.service() for servlet [Faces Servlet] in context with path [/SRC_RichFaces] threw exception [java.lang.String cannot be cast to javax.faces.component.UIComponent] with root cause
java.lang.ClassCastException: java.lang.String cannot be cast to javax.faces.component.UIComponent
at com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1941)
at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1144)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.createComponent(ComponentTagHandlerDelegateImpl.java:504)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:157)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
答案 0 :(得分:1)
您需要将它们绑定到视图和第一个属性的required
属性中,检查第二个属性的UIInput#getSubmittedValue()
是否为空且位于required
属性中第二个,检查第一个UIInput#getValue()
是否为空。
<h:selectManyCheckbox
binding="#{selectCatalogosPEC}"
required="#{empty selectCatalogosSAGARPA.submittedValue}"
>
...
</h:selectManyCheckbox>
<h:selectManyCheckbox
binding="#{selectCatalogosSAGARPA}"
required="#{empty selectCatalogosPEC.value}"
>
....
</h:selectManyCheckbox>