Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

Updating input fields with AJAX after validation error


Updating input fields with AJAX after validation error is a very old, well-known, and annoying issue for JSF developers. When an AJAX request fails in the validation phase, there is no built-in way to update the input fields with some valid values because JSF does not allow access to the model value after a validation error (usually, you want to clear up those fields or provide some default values, or even some old values provided by the same user). Of course, JSF developers found different workarounds, or used other libraries, such as PrimeFaces or OmniFaces, but a JSF solution was required.

Starting with JSF 2.2, all components that should be re-rendered (components indicated in the render attribute) will be reset if we set the resetValues attribute to true. The easiest way to understand this is to proceed with a comparison test. First, let's use an AJAX request without resetValues:

<h:form> 
  <h:message id="msgId" showDetail...