• 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

Enable/Disable button based on error messages in datatable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using PrimeFace 5.0. I have a datatable with a editable date field. Outside the datatable is a commond button, I want to enable/disable the command button based on the errors on the page.Here is the codes for teh commond button.


The command button is disabled when there are error messages on the page, on one or multiple rows in the datatable, but if I correct one of the rows error messages the button becomes enabled, even though there are errors existing on the other rows in the datatable.
 
Saloon Keeper
Posts: 27752
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
Welcome to the JavaRanch, Preethi!

That's not really how JSF is intended to work.

JSF is a lot like the old mainframe "green screen" applications in that you fill out a form and submit the form as a unit. JSF will validate the data on the form and either accept or reject the data as a unit. If it accepts it, the backing bean(s) are updated and the action method is invoked. If, on the other hand, even one item on the form is rejected, the entire form is rejected, error message(s) are posted to the JSF messages object (where they can be displayed) and the form is re-displayed. Only when the data is 100% valid will processing occur.

You can alter this behavior with AJAX, but AJAX does basically the same thing, except that it effectively creates a subset form with only a few values in it instead of all of them and conversely updates only selected parts of the display instead of completely rewriting it.

Having said that, I doubt that this will work:



For one thing, because it's attempting to put server-side constructs on the client side (View Template) and there's no accessibility.

You might try referencing a backing bean property that returns the empty/non-empty status of the message list, but there's one problem. The backing bean isn't touched if there are validation errors.

Truthfully, I think that you're better off leaving the commandButton unconditionally enabled and let JSF do what it was designed to do.

The cases where a commandButton's enablement is controlled client-side tend to be things like ensuring that required fields have values in them and certain limited constraints in data format are met, Stuff that's done in JavaScript, not in JSF. And even then it can be tricky, since JSF really doesn't like it when the visibility or enablement of JSF controls is done via client-side logic.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic