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