Thanks for your reply and for taking the time to read my frustrated whining. You've helped me catch a mistake I'd made that was going to cost me a great deal of pointless stuffing about.
Your suggestion was my first thought, too. When I tried it, Mojarra didn't seem to like it, throwing an exception (which I unfortunately failed to retain record of) about being unable to cast String to SelectItem. I concluded that it didn't support using f:selectItem and f:selectItems together in the same body.
Well, that was stupid.
My only defense is that I was tired and somewhat frustrated by other things. I'd made an accidental edit that caused the "value" property to return a String, with naturally wasn't going to work very well. I then got off on a tangent looking at the noSelectionValue attribute of f:selectItems, which I thought might hold the solution, but is missing in in Mojarra's taglib and the public javadoc due to a copy'n'paste error (
https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1793). As the last few issues I've hit have turned out to be Glassfish or Mojarra bugs I was too quick to assume that this, too, was a bug/limitation in the tools.
For anyone else finding this question: if you want to permit selection of "nothing" or "empty" in a f:selectOneMenu that's backed by a f:selectItems of a domain collection, here's how:
[code]
<h:selectOneMenu value="#{backingBean.selection}">
<f:selectItem itemValue="" itemLabel="(None)"/>
<f:selectItems value="#{backingBean.collectionProperty}" var="n" itemValue="#{n}" itemLabel="#{n.someProperty}"/>
<h:selectOneMenu>
[/code]
Anyway, now I find myself wondering why the NetBeans code generator is doing it in such a convoluted way. I don't use the generated code, but it can be useful for producing a skeleton of parts of the app as placeholders, and it was the way the generated code does it that reinforced my suspicion that maybe JSF2 didn't have an obvious and simple way of doing this.
Thanks for making me re-examine that assumption before I wasted a huge amount of time on it.
[Message sent by forum member 'ringerc']
http://forums.java.net/jive/thread.jspa?messageID=481123