I have two commandButtons on my page - "save" and "send" and lots of textInputs and other controls, almost all of them are required. User can fill in some fields and save the form - values from the form are stored in the database.
But "send" buttom musn't proceed to action processing if any of the required fields are not filled in.
In other words, I need a way to skip validation and update backing bean values and the proceed to action.
How can I achieve this?
As far as I know there isn't a way to completely skip the Process Validations phase.
One way you might be able to work around it would be to create a boolean value on your backing bean and set it to false when the Save button is clicked. In your custom validators, have them check the state of that boolean value before setting setValid(false) or adding anything to the Faces message queue.
It would mean using no built-in validators though.
Joined: Apr 26, 2011
Thank you for reply.
I was thinking about such solution, but the problem is that built-in validators are used all over the page (required attribute in textInputs set to true), and I wouldn't like to change them to custom validators.
Moreover I think it would be not the best practice to use custom validator only for checking the presence or absence of value in text field. Maybe I'm wrong..?
This doesn't exactly answer your question because it isn't a way to bypass validation, but if it is just a matter of meeting requirements for not-null fields, couldn't you have some default text that the user replaces when they start typing?
One of the major premises of JSF is that any data set in the backing bean MUST be valid. So bypassing the validators is a violation of the fundamental spirit of JSF.
Form-level validation is not conditional. If you want to validate a control only when certain buttons are pressed or other controls have specific values, that should be done in logic in the Action processor, which can then post error messages and reject the action.
Other alternatives are:
Use multiple forms on the page. Only the controls within the submitted form will be validated. However, the downside of this is that since a control can only be resident in one form, only the values in the form that was submitted will update the backing bean.
Use AJAX to limit what's routed through the system. This is basically making the uninteresting controls in the submitted form vanish from the form for the duration of the submit/response cycle.
An IDE is no substitute for an Intelligent Developer.
subject: Skip form validation but update backing bean values