Search code examples
javascriptjsf-2dom-events

onselect for h:selectManyListbox doesn't work


I have the following code:

<script type="text/javascript">
  //<![CDATA[ 
  function editSelected(selBox)
  {
    var htmlstring = selBox.options[selBox.selectedIndex].text;
    alert(htmlstring);
  }
  //]]>
</script>
...
<h:selectManyListbox
  id="titles"
  value="#{detailModel.selectedTitles}"
  size="5"
  disabled="#{detailModel.mode == detailModel.viewMode}"
  onselect="editSelected(document.getElementById('detailForm:titles'))">

  <f:selectItems
    value="#{detailModel.getCollectionAsSortableMetadataStringList(detailModel.afterObject.metadata.getTitles())}"
    var="title"
    itemLabel="#{title.value}"
    itemValue="#{title.position}"/>
</h:selectManyListbox>

With the onselect, when I click on an option of the select, there is no reaction. With onclick I have the expected behavior (a fenster with the selected text).

Do I miss something or do I something wrong?


Solution

  • This is likely an oversight in the JSF spec. The select event is not supported on <select> elements. See also HTML DOM level 2 specification chapter 1.6.5

    select

    The select event occurs when a user selects some text in a text field. This event is valid for INPUT and TEXTAREA elements.

    Note that it doesn't mention the SELECT element. I've reported it as spec issue 1113.