• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Skip form validation but update backing bean values

 
Rishat Valeye
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic