You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Rajeev Chandrasekaran (JIRA)" <de...@myfaces.apache.org> on 2006/10/30 19:46:16 UTC

[jira] Created: (MYFACES-1483) renderSelectOptions - null itemStrValue can lead to conversion error rather than required value validation error

renderSelectOptions - null itemStrValue can lead to conversion error rather than required value validation error
----------------------------------------------------------------------------------------------------------------

                 Key: MYFACES-1483
                 URL: http://issues.apache.org/jira/browse/MYFACES-1483
             Project: MyFaces Core
          Issue Type: Bug
    Affects Versions: 1.1.4
         Environment: any
            Reporter: Rajeev Chandrasekaran
            Priority: Minor


I have a drop down selectOne menu with an "empty" option as the first option. But rather than printing the empty string in the drop down menu, I want to display the text '- Select One-' instead, but still have it correspond to the empty string value for the purpose of forcing a required validation check. When I set this up (see snippets below), this leads to a conversion error on the select one component when I try to submit a form with the '-Select One-' option selected. If instead I do not try to display '-Select One-' as the empty option but just simply display the empty string as the first option in the select one component, then I correctly get a required validation error when submitting the form with the empty selection selected.

sample jsp:

						<h:selectOneMenu id="selectonecomponent" value="#{reportParameterToValueBinding.reportParameterValue}" converter="org.efs.openreports.objects.ReportParameterValue" styleClass="selectOneMenu" required="#{reportParameterToValueBinding.reportParameter.required}" >
							<f:selectItem itemValue="" itemLabel="- Select One -" />
							<f:selectItems value="#{reportParameterToValueBinding.valuesToSelectFromAsMap}" />
						</h:selectOneMenu>


I found that if I locally change org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils.renderSelectOptions from this:

....
                if (itemStrValue != null) {
                    writer.writeAttribute(HTML.VALUE_ATTR, itemStrValue, null);
                }
...

to this:
...
                if (itemStrValue != null) {
                    writer.writeAttribute(HTML.VALUE_ATTR, itemStrValue, null);
                }
		else {
		    writer.writeAttribute(HTML.VALUE_ATTR, "", null);
		}
...

then the select one component properly behaves with a required value error instead of a conversion error when sumbitting the empty form. Without this change, the component leads to rendering of the option empty as follows:

<option>- Select One-</option>

which seems to cause the browser to send '- Select One-' as the default "server" value for the component (vs the empty string).

The code change above to HtmlRendererUtils forces the option to be rendered with an explicit empty "server" value if the item value is null:

<option value="">- Select One -</option>	

which in turn results in the browser sending the empty string instead of '-Select One-' when the form is submitted with the '-Select One-' option selected.

-- 
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
-
For more information on JIRA, see: http://www.atlassian.com/software/jira