[JAVAEETUTORIAL-121] technically unspecified default is unspecified not first item Created: 07/Jul/12  Updated: 24/Apr/13  Resolved: 24/Apr/13

Status: Closed
Project: javaeetutorial
Component/s: doc
Affects Version/s: 6.0.7-5
Fix Version/s: 7.0.1

Type: Bug Priority: Major
Reporter: Brant Gurganus Assignee: Kim Haase
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

In the second to last paragraph under the "Displaying a Menu Using the h:selectOneMenu Tag" section of the "Adding Components to a Page Using HTML Tags" page at http://docs.oracle.com/javaee/6/tutorial/doc/bnarf.html, it indicates that, "If you don't provide a value, the first item in the list is selected by default." However, this is inaccurate. I have tested this out, and it renders as a <select> element with nested <options>. No <option> is marked as selected. If you look at the HTML 4.01 specification under section 17.6.1 at http://www.w3.org/TR/html4/interact/forms.html#h-17.6.1, you will see that it indicates that "If no OPTION element has the selected attribute set, user agent behavior for choosing which option is initially selected is undefined."



 Comments   
Comment by Brant Gurganus [ 07/Jul/12 ]

This unspecified selection issue also occurs in the following "Displaying Components for Selecting Multiple Values" section as well.

Comment by Kim Haase [ 09/Jul/12 ]

I've tried this, and JSF does consider the first item as selected if you use a selectOneMenu tag – but not if you use selectOneListbox or selectOneRadio. (If you output the selected values on a response page, you can see the effect.)

Comment by Brant Gurganus [ 10/Jul/12 ]

JSF considering the first item as selected is incorrect. It is the browser making that judgment. If you look at the HTML specification excerpt, nothing requires the first option to be the selected one. Most browsers will do so though. Because of the implementation detail, the first item gets submitted as the value. It's not a blank value being submitted. However, that is not JSF doing so. That is the browser doing so. Some browsers might pick the third option instead. There's no requirement that it be the first item.

If you were correct, an <h:selectOneMenu> with no value would render as:
<select><option selected="selected">a</option><option>b</option></select>

Instead, it renders as:
<select><option>a</option><option>b</option></select>

That second rendering leaves you in unspecified territory for which item to select initially.

Comment by Kim Haase [ 11/Jul/12 ]

Thanks, Brant. I expect you are correct and am checking with the spec leads to confirm, since the misinformation has been in the tutorial since EE 5.

Comment by Kim Haase [ 24/Apr/13 ]

Fixed in 7.0.1.

Generated at Sat May 23 14:09:17 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.