Issue Details (XML | Word | Printable)

Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Manfred Riem
Reporter: ssilvert
Votes: 11
Watchers: 12

If you were logged in you would be able to see more operations.

<f:validateBean disabled="true"/> doesn't work on second post-back

Created: 01/Oct/12 04:25 PM   Updated: 13/Jan/14 02:56 PM   Resolved: 30/Dec/13 04:44 PM
Component/s: None
Affects Version/s: 2.1.13
Fix Version/s: 2.2.5

Time Tracking:
Not Specified

File Attachments: 1. Text File changebundle.txt (10 kB) 30/Dec/13 04:43 PM - Manfred Riem
2. Zip Archive (10 kB) 01/Oct/12 04:25 PM - ssilvert
3. Zip Archive (4 kB) 30/Dec/13 04:43 PM - Manfred Riem

Issue Links:

Participants: alexeev_net, kennardconsulting, Manfred Riem and ssilvert

 Description  « Hide

Consider a simple case for <f:validateBean disabled="true"/>

<h:inputText id="fooBeanFooName" value="#{}">
<f:validateBean disabled="true"/>

The first time the view is rendered and posted, bean validation is correctly disabled for fooBeanFooName. However, on the second post-back of the view, bean validation is executed.

The way this is supposed to work is that the validator javax.faces.Bean is added as an excluded validator in ValidatorTagHandlerDelegateImpl.applyAttachedObject(). This part is working correctly.

However, in ComponentValidators.addDefaultValidatorsToComponent(), this is called
Set<String> disabledValidatorIds = (Set<String>)RequestStateManager.remove(ctx, RequestStateManager.DISABLED_VALIDATORS);

Since disabledValidatorIds is accessed with a "remove" instead of a "get", it will not be there if disabledValidatorIds is accessed a second time during the JSF lifecycle. And, javax.faces.Bean will no longer get excluded.

I see the same "remove" logic in ComponentValidators.addDefaultValidators().

So the sequence that causes the bug is this:

  • View is created
    1) RENDER_RESPONSE: ValidatorTagHandlerDelegateImpl.applyAttachedObject()
    2) RENDER_RESPONSE: ComponentValidators.addDefaultValidatorsToComponent()
  • Post-Back
    1) RESTORE_VIEW: ValidatorTagHandlerDelegateImpl.applyAttachedObject()
    2) RESTORE_VIEW: ComponentValidators.addDefaultValidatorsToComponent()
    3) RENDER_RESPONSE: ComponentValidators.addDefaultValidatorsToComponent()
  • Everything looks fine in the UI, but the first call to addDefaultValidatorsToComponent() removed the disabledValidatorIds. The second call to addDefaultValidatorsToComponent() added javax.faces.Bean as a validator. So, on the second Post-Back, bean validation runs and you get an unexpected validation error.

I'm attaching a simple WAR that recreates the problem.

I tried changing RequestStateManager.remove() to RequestStateManager.get(). This does fix the problem but I'm not sure it is the proper fix. I assume the original author may have had a reason for calling remove() instead of get(). Also, I'm not sure why ComponentValidators.addDefaultValidatorsToComponent() is called twice on post-back.

Manfred Riem added a comment - 26/Mar/13 05:06 PM

Can you verify this is still an issue on the latest 2.1 release?

kennardconsulting added a comment - 28/Mar/13 02:23 AM

Yes. I have re-tested with 2.1.20 and can confirm this is still an issue.

ssilvert added a comment - 25/Apr/13 03:22 PM

Any update on this one?

Manfred Riem added a comment - 02/May/13 07:21 PM

We're working on it

Manfred Riem added a comment - 30/Dec/13 04:44 PM

Applied to 2.2 branch,

svn commit -m "Fixes, make sure we only add the default validators once during initial request or postback."
Sending jsf-ri/src/main/java/com/sun/faces/component/validator/
Adding test/agnostic/facelets/core/src/main/java/com/sun/faces/test/agnostic/facelets/core/
Adding test/agnostic/facelets/core/src/main/java/com/sun/faces/test/agnostic/facelets/core/
Adding test/agnostic/facelets/core/src/main/webapp/validateBeanDisabled.xhtml
Adding test/agnostic/facelets/core/src/test/java/com/sun/faces/test/agnostic/facelets/core/
Transmitting file data .....
Committed revision 12753.

alexeev_net added a comment - 12/Jan/14 10:53 PM

Any chance this could be back-ported to the 2.1.x? Seems to be a trivial task...

Manfred Riem added a comment - 13/Jan/14 02:56 PM

Please file a back port task if you want it back ported. Thanks!