2013-05-02 45 views
1

我開發了一個複合JSF 2組件,它工作得很好。 在我使用自定義組件的頁面之一中,必須根據布爾條件呈現組合元素。 非常類似於呈現的屬性在JSF標準組件中的作用。基於布爾條件渲染複合組件

因此,我試圖執行這樣的:

<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> 

在我插入複合部件的頁面,它是這樣的:

<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()}" /> 

方法EstudiosRealizadosBean.showOtraSede()返回java.lang.Boolean的。

java.lang.IllegalArgumentException: rendered 

我怎樣才能解決這個問題:

我呈現頁面時出現以下情況例外? 我也試圖把一個布爾條件,但同樣引發異常

我張貼我的整個組件代碼:

<?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> 
+0

你試過了:? – 2013-05-02 16:06:04

回答

4

擺脫<cc:attribute name="rendered">

它的already定義在UIComponent類,其中<cc:implementation>延伸自。你不需要重新定義它。順便說一下,同樣的故事適用於idbinding屬性。

您也不需要在複合組件的第一個孩子上重新應用rendered="#{cc.rendered}"。你也可以擺脫它。 <my:composite rendered>已經應用於整個複合組件本身。

+0

感謝您的回覆。我按照建議做了,但我添加了呈現給我的自定義組件的屬性從該點到底部的頁面不會呈現 – Deibys 2013-05-02 16:58:44

+0

無法重現與Mojarra 2.1.21的問題。您正在使用哪種JSF impl /版本? – BalusC 2013-05-02 18:07:56