2012-03-06 25 views
6

下記の複合コンポーネントをボタンのグループ(ボタンの数は1〜3にすることができます)で「空のID属性はJSFでは使用できません。 Tomcat-7でMojarra 2-0-8を使用しています)。空のid属性はJSFコンポジットコンポーネントでは使用できません

<?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:button1foo:button2foo部分はテンプレートクライアントでこのように制御可能であるfoo:button3になります。

実際にには、わからない理由で動的IDが必要な場合は、コンポジットコンポーネントではなくタグファイルを作成する必要があります。

関連する問題