Hi,
I've a problem with a SelectOneMenu. On the JSF page the DropDown-box is
declared as follows:
==========
<h:selectOneMenu value="#{testcaseSelector.selectedTestcaseNumber}"
onchange="submit()"
valueChangeListener="#{testcaseSelector.valueChanged}">
<f:selectItems value="#{testcaseSelector.testcaseItems}" />
</h:selectOneMenu>
==========
As you can see, the items displayed in this list are returned by the
method getTestcaseItems. It just gathers some elements from a database
and adds a blank item at the beginning of the list. BTW: The blank item
isn't really blank. It's just an item to notify the application that the
user doesn't want to choose an item. Here is the code:
==========
SelectItem[] result = new SelectItem[testcases.size() + 1];
result[0] = new SelectItem(Long.valueOf(-1),
FacesUtil.getMessageString(facesContext,
"filter_not_specified"));
for(int i = 0; i < testcases.size(); i++) {
Testcase testcase = testcases.get(i);
result[i+1] = new SelectItem(Long.valueOf(testcase.getID()),
testcase.getToken() == null ? "" :
testcase.getToken());
}
return result;
public Long getSelectedTestcaseNumber() {
return selectedTestcase == null ? Long.valueOf(-1) :
selectedTestcase.getID();
}
==========
Initially the selectedTestcase is null, so the getter
getSelectedTestcaseNumber() returns -1 and the first element is selected
when the page is displayed.
Now I want to do some configuration when the user selects another item
from the list. Therefore I added the valueChangeListener. This works so
far. Everytime I choose another item, the listener is invoked, except
for the first (blank) item. I think it has to do with another effect I
discovered: When I tell the browser (FF 2) to show me the source of the
page, I always see the source code of the page I were before. And,
really astonishing, the source code always(!) tells me that the first
element is selected (option selected="selected" value="-1").
Does somebody know why this happens? Oh, before I forget it: I use the
latest myFaces and Tomahawk release.
Regards
Jens Weintraut
Business Process Excellence
http://www.ids-scheer.com