【问题标题】:Optimisation code jsf优化代码jsf
【发布时间】:2013-05-20 17:04:42
【问题描述】:

我想根据一个字符串的值显示一个按钮!!

我有两种类型的按钮:

按钮值 = "添加" 按钮值 = "更新"

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

还有其他方法可以让它工作吗!!我认为我的方法是错误的,因为每次都创建了一个按钮! 提前谢谢你

【问题讨论】:

  • 当render="false" 组件没有被执行...我不认为可以更优化!

标签: jsf jsf-2 primefaces


【解决方案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 值做你的业务逻辑

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-23
    • 2011-12-21
    • 2011-12-09
    • 2012-11-13
    相关资源
    最近更新 更多