【问题标题】:primefaces: how to set dynamic oncomplete event value like oncomplete="#backingbean.oncomplete"primefaces:如何设置动态 oncomplete 事件值,如 oncomplete="#backingbean.oncomplete"
【发布时间】:2015-05-06 06:11:37
【问题描述】:

我想从单个按钮显示不同的对话框取决于 backingbean 计算。就像显示一条消息“已经支付了账单”,如果客户输入重复的账单号,如果账单号没问题,则显示“账单已成功支付”。我怎样才能做到这一点?

backingbean 类:

private String oncomplete="";

public String getOncomplete() {
    return oncomplete;
}

public void setOncomplete(String oncomplete) {
    this.oncomplete = oncomplete;
}

public void bill_fees_calculation(){
    if(bill_no=="wrong"){
        oncomplete = "PF('wrongDialog').show()";        
    }
    else{
        oncomplete = "PF('rightDialog').show()"; 
    }
}

在我的 xhtml 中:

<p:commandButton oncomplete="#{backingbean.bill_fees_calculation}" icon="ui-icon-search" title="View" update=""/>

<p:dialog header="Bill Info" widgetVar="wrongDialog" modal="false" showEffect="fade" hideEffect="explode" resizable="false" closable="true" closeOnEscape="true">

        <p:outputPanel id="billDetail" autoUpdate="true" style="text-align:center;">
            <p:panelGrid  columns="2" columnClasses="label,value">                    

                <h:outputText value="Output:" />
                <h:outputText value="Bill no has been paid already" />                                        
            </p:panelGrid>
        </p:outputPanel>
    </p:dialog>

<p:dialog header="Bill Info" widgetVar="rightDialog" modal="false" showEffect="fade" hideEffect="explode" resizable="false" closable="true" closeOnEscape="true">

        <p:outputPanel id="billDetail" autoUpdate="true" style="text-align:center;">
            <p:panelGrid  columns="2" columnClasses="label,value">                    

                <h:outputText value="Output:" />
                <h:outputText value="Bill no has been paid successfully" />                                        
            </p:panelGrid>
        </p:outputPanel>
    </p:dialog>

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    您可以使用RequestContext#execute() 以编程方式声明应在当前 ajax 请求完成时执行的 JavaScript 代码。

    public void billFeesCalculation() {
        RequestContext requestContext = RequestContext.getCurrentInstance();
    
        if ("wrong".equals(billNo)) {
            requestContext.execute("PF('wrongDialog').show()");
        }
        else{
            requestContext.execute("PF('rightDialog').show()");
        }
    }
    

    请注意,我修复了原始 sn-p 中的其他 (severe) 问题。


    与具体问题无关,如果您只使用一个带有动态(面孔)消息的对话框,它会更干净和DRY 代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-02
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多