jsf 2 - render composite component based on a Boolean condition -
i developed composite jsf 2 component, , working pretty well. in 1 of pages use custom component, necessary composite component should rendered according boolean condition. pretty similar rendered attribute works in jsf standard components.
so tried implement this:
<cc:interface componenttype="ciudadcomponent"> <cc:attribute name="paises" type="java.util.list" required="true" /> <cc:attribute name="departamentos" type="java.util.list" required="true" /> <cc:attribute name="ciudades" type="java.util.list" required="true" /> <cc:attribute name="name" type="java.lang.string" required="true" /> <cc:attribute name="value" type="org.colfuturo.model.to.ciudadto" required="true"## heading ## /> <cc:attribute name="etiquetapais" type="java.lang.string" /> <cc:attribute name="etiquetabotonok" type="java.lang.string" /> <cc:attribute name="etiquetabotoncancelar" type="java.lang.string" /> <cc:attribute name="etiquetadepartamento" type="java.lang.string" /> <cc:attribute name="etiquetaciudad" type="java.lang.string" /> <cc:attribute name="styleclass" type="java.lang.string" /> <cc:attribute name="backgroundcolor" type="java.lang.string" default="#b0c4de" /> <cc:attribute name="rendered" type="java.lang.boolean" required="false" default="true" /> </cc:interface> <cc:implementation> <h:inputtext id="seleccionado" binding="#{cc.seleccionado}" disabled="true" rendered="#{cc.rendered}"> <f:converter converterid="ciudadconverter" /> </h:inputtext> </cc:implementation>
in page insert composite component, this:
<gambatte:ciudad paises="#{menutreebean.listapaises}" departamentos="#{menutreebean.listadepartamentos}" ciudades="#{menutreebean.listaciudades}" styleclass="myselectstyle" etiquetabotonok="#{msg['perfil.common.btnok']}" etiquetabotoncancelar="#{msg['perfil.common.btncancelar']}" etiquetapais="#{msg['perfil.common.lblpais']}" etiquetadepartamento="#{msg['perfil.common.lbldepartamento']}" etiquetaciudad="#{msg['perfil.common.lblciudad']}" name="otrasedeciudad" value="#{estudiosrealizadosbean.otrasedeciudad}" rendered="#{estudiosrealizadosbean.showotrasede()}" />
the method estudiosrealizadosbean.showotrasede() returns java.lang.boolean.
i following exception when rendering page:
java.lang.illegalargumentexception: rendered
how can solve ? have tried put boolean condition, same exception raised
i posting whole component code:
<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j" xmlns:cc="http://java.sun.com/jsf/composite"> <cc:interface componenttype="ciudadcomponent"> <cc:attribute name="paises" type="java.util.list" required="true" /> <cc:attribute name="departamentos" type="java.util.list" required="true" /> <cc:attribute name="ciudades" type="java.util.list" required="true" /> <cc:attribute name="name" type="java.lang.string" required="true" /> <cc:attribute name="value" type="org.colfuturo.model.to.ciudadto" required="true" /> <cc:attribute name="etiquetapais" type="java.lang.string" /> <cc:attribute name="etiquetabotonok" type="java.lang.string" /> <cc:attribute name="etiquetabotoncancelar" type="java.lang.string" /> <cc:attribute name="etiquetadepartamento" type="java.lang.string" /> <cc:attribute name="etiquetaciudad" type="java.lang.string" /> <cc:attribute name="styleclass" type="java.lang.string" /> <cc:attribute name="backgroundcolor" type="java.lang.string" default="#b0c4de" /> <cc:attribute name="cacheinterface" type="org.colfuturo.business.interfaces.iserviciocache" required="false" /> </cc:interface> <cc:implementation> <span id="#{cc.clientid}" style="white-space:nowrap"> <h:inputtext id="seleccionado" binding="#{cc.seleccionado}" disabled="true" > <f:converter converterid="ciudadconverter" /> </h:inputtext> <a4j:commandbutton execute="@none" immediate="true" value=".." oncomplete="document.getelementbyid('#{cc.attrs.name}').style.position = 'absolute'; document.getelementbyid('#{cc.attrs.name}').style.display = 'inline-block';" /> <br /> <ui:fragment> <div id="#{cc.attrs.name}" layout="block" style="border-radius: 10px; background-color:#{cc.attrs.backgroundcolor}; display:none;" > <table border="0"> <tr> <td><h:outputtext value="#{cc.attrs.etiquetapais}" /></td> <td> <rich:select id="pais" binding="#{cc.pais}" styleclass="#{cc.attrs.styleclass}" defaultlabel="seleccione un paĆs" > <f:selectitems value="#{cc.listapaises}" /> <f:ajax event="selectitem" execute="@this" listener="#{cc.updatepais}" /> </rich:select> </td> </tr> <tr> <td><h:outputtext value="#{cc.attrs.etiquetadepartamento}" /></td> <td> <rich:select id="departamento" binding="#{cc.departamento}" styleclass="#{cc.attrs.styleclass}" defaultlabel="seleccione un departamento" > <f:selectitems value="#{cc.listadepartamentos}" /> <f:ajax event="selectitem" execute="@this" listener="#{cc.updatedepartamento}" /> </rich:select> <a4j:outputpanel layout="block" binding="#{cc.panelotrodepartamento}" > <h:inputtext id="otrodepartamento" binding="#{cc.otrodepartamento}" > <f:ajax event="keyup" listener="#{cc.enablesubmit}" execute="@this otraciudad" /> </h:inputtext> </a4j:outputpanel> </td> </tr> <tr> <td><h:outputtext value="#{cc.attrs.etiquetaciudad}" /></td> <td> <rich:select id="ciudad" binding="#{cc.ciudad}" styleclass="#{cc.attrs.styleclass}" defaultlabel="seleccione una ciudad" > <f:selectitems value="#{cc.listaciudades}" /> <f:ajax event="selectitem" execute="@this" listener="#{cc.updateciudad}" /> </rich:select> <a4j:outputpanel layout="block" binding="#{cc.panelotraciudad}" > <h:inputtext id="otraciudad" binding="#{cc.otraciudad}" > <f:ajax event="keyup" listener="#{cc.enablesubmit}" execute="@this otrodepartamento" /> </h:inputtext> </a4j:outputpanel> </td> </tr> <tr> <td> <h:commandbutton value="#{cc.attrs.etiquetabotonok}" disabled="true" binding="#{cc.botonacccion}" onclick="document.getelementbyid('#{cc.attrs.name}').style.position = 'absolute'; document.getelementbyid('#{cc.attrs.name}').style.display = 'none';" > <f:ajax execute="ciudad" listener="#{cc.submit}" /> </h:commandbutton> </td> <td> <a4j:commandbutton value="#{cc.attrs.etiquetabotoncancelar}" execute="@none" immediate="true" oncomplete="document.getelementbyid('#{cc.attrs.name}').style.position = 'absolute'; document.getelementbyid('#{cc.attrs.name}').style.display = 'none';" /> </td> </tr> </table> </div> </ui:fragment> <div style="display:block;" ></div> </span> </cc:implementation> </html>
get rid of <cc:attribute name="rendered">
.
it's already defined in uicomponent
class, <cc:implementation>
extends from. don't need redefine it. same story applies id
, binding
attributes, way.
you don't need re-apply rendered="#{cc.rendered}"
on composite component's first child. can rid of it. <my:composite rendered>
applies on whole composite component itself.
Comments
Post a Comment