2013-05-20 171 views
-1

我想根據字符串的值顯示一個按鈕!優化代碼jsf

我有兩個類型的按鈕:

按鈕值=「添加」按鈕, 值=「更新」

<p:column> 
      <f:facet name="header"> 
        Result 
      </f:facet> 
      <h:outputText value="#{LigneXL.resultat}" /> 
      <p:commandButton value="ADD NEW" rendered="#{LigneXL.resultat eq 'Not exist'}"></p:commandButton> 
      <p:commandButton value="MAJ"  rendered="#{LigneXL.resultat eq 'Is FMD'}"></p:commandButton> 
     </p:column> 
     <p:column> 

有另一種方式,使其作品!我覺得我的梅索德是錯誤,因爲每次有一個按鈕創建! 預先感謝您

+1

當渲染=」假「的組件不執行......我不認爲這可能會更優化! –

+0

謝謝@ALexandreLavoie –

回答

1

下面是我在試圖優化代碼,

 <p:column headerText="Result"> 
      <h:outputText value="#{LigneXL.resultat}" /> 
      <p:commandButton value="#{LigneXL.resultat eq 'Not exist'?'ADD NEW':'MAJ'}" rendered="#{(LigneXL.resultat eq 'Not exist') or LigneXL.resultat eq 'Is FMD'}"> 
       <f:setPropertyActionListener value="#{LigneXL.resultat}" target="#{yourBean.targetString}"/> 
      </p:commandButton> 
     </p:column> 

請在yourBean一個String對象,並根據targetString價值做你的業務邏輯