The moose likes JSF and the fly likes Ajax call, backing bean and validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Ajax call, backing bean and validation" Watch "Ajax call, backing bean and validation" New topic

Ajax call, backing bean and validation

Tommaso Tama

Joined: Oct 13, 2010
Posts: 11
Hi to all, here I'm again!

After running around and crawling the web, I have my main issue back again on my desk.
Please, help me to undertand if there is a solution to my ancient problem.

The scenario in quite simple:

- jsf 1.2
- richfaces
- ajax

Two required input text, rollo and job1.
An a4j:commandButton that updates the value oh the backing bean property linked to rollo input text.

It works fine: the button updates the backing bean and the input text on the page shows the updated value.
BUT when I submit the form and I trigger a validation error of a component JOB1 on the, the a4j:commandButton updates only the backing bean and not the field on the page. Indeed, if the component with validation problem is the one designed to be updated by the ajax call, IT WORKS. But if ANY other component is invalid, the ajax button can update only the backing bean and not the component. Maybe after the submit something happens that block the update. Losing my head, sorry.

is there a logic reason for that behaviour? Is there a workaround?

Many thanks!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

JSF does not permit partial updating of a bean where only valid items update. If any item selected for update is invalid, the backing bean will not be updated.

Normally, that means all property references on the submitted form. When using AJAX (a4j), you can limit the properties that are submitted/validated if you desire. However, you have not done this, so all properties will be submitted and subjected to validation.

When a backing bean property is updated using a4j, its value will only update on the View if the id of the control that displays its value has been included in a reRender request.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Ajax call, backing bean and validation
It's not a secret anymore!