1
votes

My screen looks like this

enter image description here

The problem is that, when I press the Reset Button, the Code input field does not clear, as it was supposed to.

The jsf is the following:

<h:form id="form1">
    <h:inputText id="code" value="#{MyBean.data.code}" />

    <a4j:commandButton  immediate="true"
        action="#{MyBean.clear}" render="form1" update="@form">
    </a4j:commandButton>

    <h:outputText value="#{session.lastAccessedTime}">
          <f:convertDateTime pattern="HH:mm:ss.SSS" type="date" />
    </h:outputText>
</h:form>

The bean code is the following:

public class MyBean {

    DataInnerClass data = new DataInnerClass(); 
    //getter and setter for data

    public class DataInnerClass {

        private String code;
        //getter and setter for code

        public DataInnerClass() {
            super();
        }
    }

    public void clear() {        
        data = new DataInnerClass();
        Logger.getLogger( MyBean.class.getName() ).log(Level.SEVERE, "data.code="+data.code);
        //logs data.code=null
    }
}

When I press the Reset button, the log shows that the value of the field code has become null (its no longer 'ZZ'); i also know that the screen refreshes successfully, because i have displayed the current time, which updates after every click. So the backing bean property changes, the screen refreshes, and still the input field keeps the same value. Do you have any idea why this is happening?

1

1 Answers

2
votes

I found useful BalusC's answer on: How can I populate a text field using PrimeFaces AJAX after validation errors occur?

I understand from there that, in the case of some validation error, the input field will keep the value entered by the user, and will be out of sync with the backing bean. I must emphasize that in my case, there were no validation errors, but still, adding an <f:ajax resetValues> to the commandButton worked for me.

A concrete example of the resetValues attribute is on https://jsflive.wordpress.com/2013/06/20/jsf-22-reset-values/

Finally, my button tag looks like this:

<a4j:commandButton  immediate="true"
    action="#{MyBean.clear}" render="form1" update="@form">
    <f:ajax render="code" resetValues="true" />
</a4j:commandButton>