2

In JSFs validation phase, in what order are input fields validated?

What I thought about trying is the following: I have a group of input fields that may pass or fail conversion/validation. Also, I would like to have some input with a custom validator that produces a different outcome depending on whether all other fields passed validation or not. I can check the FacesContext for any previous messages, but I would have to make sure that this custom converter is called after all other fields have been checked, hence the above question. Is it simply the order in which they are defined in the Facelets-Page? If so, would this order be guaranteed?

Louise
  • 1,451
  • 1
  • 18
  • 40

1 Answers1

2

Is it simply the order in which they are defined in the Facelets-Page?

Basically, yes. The component tree will be processed recursively "the usual way". For each component first the component itself will be processed and then each of its child components in sequence.


If so, would this order be guaranteed?

Yes. This is stated in the JSF 2.0 specification:

2.2.3 Process Validations

...

During the Process Validations phase of the request processing lifecycle, the JSF implementation must call the processValidators() method of the UIViewRoot of the tree. This will normally cause the processValidators() method of each component in the tree to be called recursively, as described in the API reference for the UIComponent.processValidators() method.

...

The custom converter should thus be referenced by the last component or a "stub" <h:inputHidden> component after all of the desired components. The desired components can be passed through by component bindings. See also this related answer: JSF doesn't support cross-field validation, is there a workaround?

As a completely different alternative, you could consider wrapping the whole thing in a composite.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • personal question: do you sleep? Sometimes, after yet another faster-than-2-min response one starts to wonder... ;) – Louise Oct 17 '12 at 12:28
  • Regarding your edit: What would happen if I wrap it in a composite component? Does the component itself have an invalid status that depends on its contents? (PS: got notified of some comment of yours but can't see it here. Did you delete it?) – Louise Oct 17 '12 at 14:17