2013-05-20 173 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价值做你的业务逻辑