2012-03-06 2 views
6

버튼 그룹에 대해 아래에서 언급 한 복합 구성 요소를 사용하는 동안 "빈 ID 속성이 JSF에서 허용되지 않습니다"라는 문제가 발생했습니다 (나는 Mojarra 2-0-8을 Tomcat-7에서 사용한다.)JSF 컴포지트 구성 요소에서 빈 id 속성을 사용할 수 없습니다.

<?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:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:composite="http://java.sun.com/jsf/composite"> 


    <composite:interface>  
     <composite:attribute name="buttonCount" /> 
     <composite:attribute name="button1Id" /> 
     <composite:attribute name="button1Style" /> 
     <composite:attribute name="button1Action" /> 
     <composite:attribute name="button2Id" /> 
     <composite:attribute name="button2Style" /> 
     <composite:attribute name="button2Action" /> 
     <composite:attribute name="button3Id" /> 
     <composite:attribute name="button3Style" /> 
     <composite:attribute name="button3Action" /> 

    </composite:interface> 
    <composite:implementation>  
     <h:commandButton rendered = "#{cc.attrs.buttonCount ge '1'}" id="#{cc.attrs.button1Id}" styleClass="#{cc.attrs.button1Style}"> 
      <f:ajax listener="#{cc.attrs.button1Action}" immediate="true"/>          
     </h:commandButton> 
     <h:panelGroup rendered = "#{cc.attrs.buttonCount ge '2'}"> 
      <h:commandButton id="#{cc.attrs.button2Id}" styleClass="#{cc.attrs.button2Style}"> 
       <f:ajax listener="#{cc.attrs.button2Action}" immediate="true"/>          
      </h:commandButton> 
     </h:panelGroup> 
     <h:panelGroup rendered = "#{cc.attrs.buttonCount eq '3'}"> 
      <h:commandButton id="#{cc.attrs.button3Id}" styleClass="#{cc.attrs.button3Style}"> 
       <f:ajax listener="#{cc.attrs.button3Action}" immediate="true"/>          
      </h:commandButton> 
     </h:panelGroup> 
    </composite:implementation> 
</html> 

위의 CC의 사용.

<Buttons:myButton txtHeader="Title" txtDescription="text1" 
        txtAction="TextAction." button1Style="btnSave" buttonCount ="1" button1Id="btnSaveConf" button1Action="#{MyBean.save()}"></Buttons:myButton> 

메인 페이지의 수 또는 모든 유사 입력을 기반으로 버튼을 동적으로 생성하는 더 좋은 방법은 없습니다. 참고 : - ID, 스타일 및 작업의 이름이 달라야합니다.

답변

5

id 속성에서 렌더링 시간 EL을 사용할 수 없습니다. 대신 고정 ID를주고 합성 자체에 ID를 부여하십시오. 따라서, 예를 들어 : 구현

<h:commandButton id="button1" ... /> 
<h:commandButton id="button2" ... /> 
<h:commandButton id="button3" ... /> 

에서와

<buttons:myButton id="foo" ... /> 

그런 다음 foo:button1, foo:button2foo 부분은 템플릿 클라이언트에 따라서 제어가 가능 foo:button3 될 것이다.

실제로에 약간의 이유 때문에 동적 ID가 필요한 경우 복합 구성 요소가 아닌 태그 파일을 만들어야합니다.

관련 문제