簡體   English   中英

如何以編程方式將素面 selectOneMenu 設置為 OldValue

[英]how to set to OldValue the primefaces selectOneMenu programmatically

Java / PrimeFaces 3.5

我想回滾 primeFaces selectOneMenu Old Value 並重新加載它以更新屏幕上的組件。

  1. selectOneMenu 加載了 FIRST、SECOND、THIRD 值,默認值設置為 FIRST

  2. 如果我將 selectOneMenu 值從 FIRST 更改為 THIRD,我想再次將其設置為 FIRST。

     <p:selectOneMenu id="statusProposta" value="#{propostaBean.propostaComercial.proposta_Status}" items="#{propostaBean.statusProposta}" valueChangeListener="#{propostaBean.regraStatusProposta}" > <p:ajax event="change" process="statusProposta" update="statusProposta" /> <f:selectItem itemLabel="" itemValue="" /> <f:selectItems value="#{propostaBean.statusProposta}" /> </p:selectOneMenu>

StatusProposta :

公共枚舉 StatusProposta { FIRST、SECOND 和 THIRD .....

豆角,扁豆 :

public void regraStatusProposta(ValueChangeEvent ev){
   **I dont know how to set the old value and update it in screen.**
   ...
public void regraStatusProposta(ValueChangeEvent ev){    
//get old value first 
Object oldValue=ev.getOldValue();    
}

有關ValueChangeEvent API的更多信息

http://forum.primefaces.org/viewtopic.php?f=3&t=36447

重置輸入

博客文章:重置JSF 2.2的值

霍華德在primefaces論壇上發布了

http://www.primefaces.org/showcase/ui/resetInput.jsf

public void reset() {  
    RequestContext.getCurrentInstance().reset("form:panel");  
}  

我為 PrimeFaces 創建了這個實用程序,它檢查組件是否可見,否則它會在控制台上記錄一個 WARN。

public static void resetUIComponents(String... componentsId) {
    for (String id : componentsId) {
        if (FacesContext.getCurrentInstance().getViewRoot().findComponent(id) != null) {
            PrimeFaces.current().resetInputs(id);
        }
    }
}

所以你可以像這樣使用它:

ViewUtils.resetUIComponents("form:id1", "form:id2")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM