This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSF and the fly likes Skip form validation but update backing bean values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSF
Bookmark "Skip form validation but update backing bean values" Watch "Skip form validation but update backing bean values" New topic

Skip form validation but update backing bean values

Rishat Valeye

Joined: Apr 26, 2011
Posts: 6
Hi, everyone!

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?

Thanks in advance for your help
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 200

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.
Rishat Valeye

Joined: Apr 26, 2011
Posts: 6
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..?
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 200

One thing you can do is use a JSF extension like ICEfaces that allows you to do a partial submit and bypass the built-in JSF required field validators.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

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?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17018

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.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: Skip form validation but update backing bean values
It's not a secret anymore!