• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Skip form validation but update backing bean values

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I found some pretty shells, some sea glass and this lovely tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic