I am working with JSF 1.2 and could use a little advice. I have an FMB (PlanFMB.java) that contains an array list of select items and a single selectedItem.
When the page loads, the getProjects() method is correctly called and displays the Projects as expected. Strange thing is though, the getSelectedItem() method is called three times (once of each project). Not sure if this is typical behavior:
SystemOut O getSelectedItem = null
SystemOut O getSelectedItem = null
SystemOut O getSelectedItem = null
Also, I have a command link in my JSP, that when clicked does the same thing, calls the getSelectedItem() method three times:
<h:commandLink action="#{planDocBean.classAction}" id="classActionENLink">
PlanFMB.java
String selectedItem = null;
private List<SelectItem> selectItems = null;
public String getSelectedItem() {
System.out.println("getSelectedItem = " + selectedItem);
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
System.out.println("setSelectedItem = " + selectedItem);
}
public List<SelectItem> getProjects() {
if (selectItems == null) {
selectItems = new ArrayList<SelectItem>();
selectItems.add(new SelectItem("Project1", "Project1"));
selectItems.add(new SelectItem("Project2", "Project2"));
selectItems.add(new SelectItem("Project3", "Project3"));
}
return selectItems;
}
<h:selectOneMenu id="items" value="#{planDocBean.selectedItem}">
<f:selectItems value="#{planDocBean.projects}" />
</h:selectOneMenu>
One last thing, the actual selected item is not retained in the select menu when the page reloads.
Any feedback much appreciated. Thanks!