JSF Showcase

f:resetValues

f:resetValues appeared since JSF 2.2 to fix a behavior that could appear under some conditions that caused some UI components to not reflect the real bean state. This Facelet can be used for non-AJAX request, if using f:ajax, just use f:ajax resetValues attribute.

General Usage

Use for to configure which single component value you want to be reset for avoiding behavior mentioned above. Use render to add a list of clientId (not id as usual) to which the values would be reset. Important note: this attribute doesn't support any word for some scopes like @form, so you should add each of them. To check this behavior, follow these steps:
  • Add some text in one of the fields below, then click on the Submit button
  • A validation error will show up. This is expected behavior at this point.
  • Now click on Reset. actionListener is invoked and resets both fields, so the inputText should be empty after this request, which wouldn't be true if f:resetValues was not used.

    Source Code

    <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
    	xmlns:h="http://xmlns.jcp.org/jsf/html"	xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    
    	<h:form id="resetFrm">
    		<h:messages/>		
    		<h:inputText id="required1" value="#{resetValuesBackingBean.requiredText1}" required="true"/>
    		<h:inputText id="required2" value="#{resetValuesBackingBean.requiredText2}" required="true"/>
    		<h:commandButton value="#{i18n['submit']}" />
    
    		<h:commandButton actionListener="#{resetValuesBackingBean.actionListener}" immediate="true"
    			value="#{i18n['reset']}">
    			<f:resetValues render="resetFrm:example1:required1 resetFrm:example1:required2"/>				
    		</h:commandButton>								
    	</h:form>
    
    </ui:composition>
    @ManagedBean
    @RequestScoped
    public class InputTextModelBean {
    
    	private Date date = new GregorianCalendar().getTime();
    	private String text;
    
    	public Date getDate() {
    		return date;
    	}
    
    	public String getText() {
    		return text;
    	}
    
    	public void setDate(Date date) {
    		this.date = date;
    	}
    
    	public void setText(String text) {
    		this.text = text;
    	}
    }
    @ManagedBean
    @RequestScoped
    public class ResetValuesBackingBean {
    
    	private String requiredText1;
    	private String requiredText2;
    
    	public void actionListener() {
    		postConstruct();
    	}
    
    	public String getRequiredText1() {
    		return requiredText1;
    	}
    
    	public String getRequiredText2() {
    		return requiredText2;
    	}
    
    	@PostConstruct
    	public void postConstruct() {
    		this.requiredText1 = null;
    		this.requiredText2 = null;
    	}
    
    	public void setRequiredText1(String requiredText) {
    		this.requiredText1 = requiredText;
    	}
    
    	public void setRequiredText2(String nonRequiredText) {
    		this.requiredText2 = nonRequiredText;
    	}
    
    }
Liferay Faces Bridge Implementation 4.0.0 + Showcase Common 3.0.0 + Liferay Faces Util 3.0.1-SNAPSHOT + Mojarra 2.2.13