3

The Primefaces p:selectOneMenu component does not seem to bring focus to a previously selected item. For example, if I have a menu of countries set up as follows

    <p:selectOneMenu id="countryMenu" value="#{myBean.selectedCountry}">
        <f:selectItem value="#{null}" itemLabel="Please select a Country..."/>
        <f:selectItems value="#{myBean.countries}" var="country" 
                       itemValue="#{country.code}" 
                       itemLabel="#{country.name}"/>
        <p:ajax update="anotherComponent"/>
    </p:selectOneMenu>

and I select a country from the list, then click on the menu again it displays the list of countries from the beginning. It does retain the selected country - it just doesn't scroll down and focus on it.

The standard JSF h:selectOneMenu displays the expected behaviour - it opens with the previously selected country visible.

Is there some trick to this or is this a bug?

It also has a number of other quirks with how it responds to keyboard input (pressing up/down when the menu has focus doesn't open the menu, for example), which is a little frustrating.

I'm using:

  • Primefaces 3.1
  • Glassfish 3.1.1
  • NetBeans 7.1
James Bassett
  • 9,458
  • 4
  • 35
  • 68
  • Well, that's clearly a bug (at least, lack of feature) in PrimeFaces and you're probably also already aware about that. We can't do much for you here other than suggesting you to report a bug over there, or to rewrite/override the renderer and/or JavaScripts. – BalusC Feb 13 '12 at 12:06
  • FYI, you can search for and/or report issues with Primefaces here: http://code.google.com/p/primefaces/issues/list – maple_shaft Feb 13 '12 at 12:11
  • @maple_shaft Yeah, i looked before posting this question, but there's no current issues related to this. I just wanted to make sure it really is a bug before posting an issue. – James Bassett Feb 13 '12 at 22:26
  • Ok, still happening in 3.4, so I've raised an [issue](http://code.google.com/p/primefaces/issues/detail?id=4693) – James Bassett Sep 27 '12 at 02:18

3 Answers3

0

If you update to Primefaces 3.4 (current version at the moment), you still have a similar behavior, which is not expected.

Event if the first item has the noSelectionOption="true" you get the same behavior which seems to be a bug in review, and it is reported here and here. Also there is a forum thread about it.

But you could try using the itemDisabled property, as it solved this problem for me:

<p:selectOneMenu id="hero" value="#{bean.hero}">
    <f:selectItem itemLabel="Select..." itemDisabled="true" />
    <f:selectItems var="item" value="#{bean.heroes}" itemLabel="#{item.name}" />
</p:selectOneMenu>

I hope it helps.

rbento
  • 9,919
  • 3
  • 61
  • 61
  • Those issues seem unrelated, and `itemDisabled` makes no difference. I've raised an issue, so hopefully it'll get fixed soon :) – James Bassett Sep 27 '12 at 02:21
0

Ok, this appears to have been fixed!

I ran some tests with various versions of Primefaces with the following results:

  • 3.1 - didn't work

  • 3.2 - didn't work

  • 3.3 - didn't work (previously selected value flickers briefly, then the first menu item is displayed)

  • 3.4 - works as expected

Note: I did need to clear my browser cache (in Chrome and Firefox) when upgrading from 3.3 to 3.4 (the items weren't selectable at all until I did this).

James Bassett
  • 9,458
  • 4
  • 35
  • 68
0

It's not a bug. You just need to override equalsTo(Object o) and compareTo(Object o) methods in Country class.

It'll work OK after you do it.

pjumble
  • 16,880
  • 6
  • 43
  • 51
skouda
  • 396
  • 3
  • 2
  • This doesn't explain why it works in `h:selectOneMenu`. The `compareTo()` is unnecessary, it won't be used. The `equalsTo()` does not exist, I'll assume that you mean `equals()`. But if this was absent or poorly implemented, the `h:selectOneMenu` would also have failed. – BalusC Mar 30 '12 at 13:46
  • 1
    The exact same problem can be seen on the Primefaces showcase (the 'pojo' example at http://www.primefaces.org/showcase/ui/selectOneMenu.jsf). One of these days I'll report it. Oh and BalusC - thanks for your tireless SO answering, nearly every useful JSF article I find has your name on it somewhere! – James Bassett Mar 31 '12 at 09:19