[
http://issues.apache.org/jira/browse/MYFACES-72?page=comments#action_59822 ]
Brett Langston commented on MYFACES-72:
---------------------------------------
OK, I did some research and looked up the spec. There is conflicting
information, depending on where you look.
First, looking at the JavaServer Faces Specification yields some clues. In
section 3.5.4, "Validation Processing", it states:
"During the Process Validations phase of the request processing lifecycle (as
described in Section 2.2.3 "Process Validations"), the JSF implementation will
ensure that the validate() method of each registered Validator, the method
referenced by the validator property (if any), and the validate() method of the
component itself, is called for each EditableValueHolder component in the
component tree, regardless of the validity state of any of the components in
the tree...
"...The render-independent property required is a shorthand for the function of
a "required" validator. If the value of this property is true and the component
has no value, the component is marked invalid and a message is added to the
FacesContext instance."
So, in summary, section 3.5.4 of the spec says, among other things, that:
1) The validate() method of a component must get called in the Process
Validations phase
2) If the "required" property is true and the component has no value, it's
marked invalid
Now let's check out section 2.2.3, "Process Validations", where it states:
"As part of the creation of the view for this request, zero or more Validator
instances may have been registered for each component. In addition, component
classes themselves may implement validation logic in their validate() methods.
"During the Process Validations phase of the request processing lifecycle, the
JSF implementation must call the processValidators() method of the UIViewRoot
of the tree. This will normally cause the processValidators() method of each
component in the tree to be called recursively, as described in the API
reference for the UIComponent.processValidators() method."
Alright, it tells us to check out the API reference for
UIComponent.processValidators(). Reading it, one finds that eventually the
validate() method of UIInput gets called in the case of a selectOneRadio. Here
is part of what the API docs say about that:
"public void validate(javax.faces.context.FacesContext context)
Perform the following algorithm to validate the local value of this UIInput.
* Retrieve the submitted value with getSubmittedValue(). If this
returns null, exit without further processing. (This indicates that no value
was submitted for this component.)"
I guess this is the spec you are talking about. Here, it says that if the
submitted value is null, to exit immediately.
I can see this for the case where required != true, because in that case, if
the user submits a null value, then one can just leave things alone and the
component will just continue to have its previous value.
However, in the case where required=true, if the user submits a null value, I
think that validate() should check the previous value. If it is also null,
then the component should be marked invalid.
In conclusion, it looks like there is a contradiction in the two specs. The
"JavaServer Faces Specification" says that a component with required=true and
no value doesn't validate, but the "JavaServer Faces (1_1_01) API Reference"
says not to bother validating in this case.
Maybe this is something that should be submitted to the people working on the
spec, so that the apparent contradiction can be cleared up. Or, am I looking
at this incorrectly?
It doesn't look to hard to fix in the MyFaces code, but of course it should not
be changed if it is going to violate the spec. Sorry to be so long-winded, but
I spent a bit of time looking all this stuff up, and I thought it might be
useful to write it down for others to read instead of just keeping it in my
head. Maybe. :)
> HtmlSelectOneRadio does not correctly validate the required case
> ----------------------------------------------------------------
>
> Key: MYFACES-72
> URL: http://issues.apache.org/jira/browse/MYFACES-72
> Project: MyFaces
> Type: Bug
> Versions: 1.0.8 beta
> Environment: WSAD 5.1.2, IE 6
> Reporter: Heath Borders-Wing
>
> If an HtmlSelectOneRadio does not initially have a value, none of its options
> are initially rendered as selected. If none are selected and a form submit
> occurs IE 6 (possibly others browsers?) does not submit any name/value pair
> for that input. In the renderer, this is just ignored, and no error is
> thrown. It would probably be best to put logic in the renderer to account
> for this case.
> I can do this, but I wanted opinions on the issue before I wrote the fix.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira