0

Java / PrimeFaces 3.5

I would like to rollback primeFaces selectOneMenu Old Value and reload it updating the component at screen.

  1. The selectOneMenu is loaded with FIRST, SECOND , THIRD values and default value is setted with FIRST

  2. If I change the selectOneMenu value From FIRST to THIRD, I would like to set it to FIRST again.

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

public enum StatusProposta { FIRST,SECOND and THIRD .....

Bean :

public void regraStatusProposta(ValueChangeEvent ev){
   **I dont know how to set the old value and update it in screen.**
   ...
Makky
  • 17,117
  • 17
  • 63
  • 86
Al2x
  • 1,001
  • 5
  • 26
  • 37

3 Answers3

0
public void regraStatusProposta(ValueChangeEvent ev){    
//get old value first 
Object oldValue=ev.getOldValue();    
}

More on ValueChangeEvent API

Makky
  • 17,117
  • 17
  • 63
  • 86
  • Thats no make sense. where will I set oldValue in the component ? you are setting just an oldValue Object. – Al2x Feb 17 '14 at 16:11
  • @Al2x I think you either very new to Java or its your bad day today. This makes sense dude. You get the old value now its upto you where you assign it . We're here to help you not to complete your whole assignment. – Makky Feb 17 '14 at 16:36
  • I set my entity property to the oldValue and update it with ajax but the new value keeps on the component screen – Al2x Feb 17 '14 at 16:49
  • 1. The selectOneMenu is previously loaded with FIRST,SECOND AND THIRD values. when I load my form it comes with default the FIRST one. 2- If I choose THIRD value, I need my bean set the default selectOneMenu value to FIRST again automatically and refresh the component at screen. got it ? – Al2x Feb 17 '14 at 16:55
  • @Al2x Why would you want your selectOneMenu to go back to FIRST value again ,explain that? – Makky Feb 17 '14 at 16:57
  • Its my business rule. If customer select one option differente from what is expected I need to set the component with the old value again. got it ? – Al2x Feb 17 '14 at 17:35
0

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

resetinput

blog post: Reset Values for JSF 2.2

posted by Howard at primefaces forum

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

public void reset() {  
    RequestContext.getCurrentInstance().reset("form:panel");  
}  
Al2x
  • 1,001
  • 5
  • 26
  • 37
0

I've created this utility for PrimeFaces which checks if the component is visible, otherwise it would log a WARN on console.

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

So you can use it like this:

ViewUtils.resetUIComponents("form:id1", "form:id2")
MatPag
  • 41,742
  • 14
  • 105
  • 114