Portal 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:ajaxresetValues
attribute.
General Usage
Usefor
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.Codi font
<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:required1 resetFrm:required2" /> </h:commandButton> </h:form> </ui:composition>
@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 requiredText1) { this.requiredText1 = requiredText1; } public void setRequiredText2(String requiredText2) { this.requiredText2 = requiredText2; } }
Liferay Faces Bridge Implementation 5.0.0 + Liferay Faces Portal 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20