SelectItemGroup.........
Trying to write simple application to adjust with SelectItemGroup in JSF.
It seems that all alright… but I couldn’t even display my .jsp…. Tomcat throws exceptionCan't instantiate class..
Would you help me to deal with it?
--
my jsp page
<f:view>
<h1><h:outputText value="JavaServer Faces" /></h1>
<h:message id="error" for="addItemField" errorStyle="color:red"/>
<h:form id="addItemForm">
<h:outputLabel for="addItemField">
<h:outputText value="Add new item"/>
</h:outputLabel>
<h:inputText id="addItemField" required="true" value="#{bbean.newItem}"/>
<h:commandButton value="Add item" action="#{bbean.addNewItem}"/>
</h:form>
<h:selectOneListbox style="width:16%">
<f:selectItems value="#{bbean.itemsGroup}"/>
</h:selectOneListbox>
</f:view>
backing bean class
package backinbean;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
publicclass BackingBeanClass{
private List itemsList;
private String newItem;
private SelectItemGroup itemsGroup;
public BackingBeanClass(){
itemsList=new ArrayList();
itemsGroup =new SelectItemGroup("--registered items--",null, false, (SelectItem[])itemsList.toArray());
}
publicvoid setNewItem(String newItem){
this.newItem = newItem;
}
public String getNewItem(){
return newItem;
}
public SelectItemGroup getItemsGroup(){
return itemsGroup;
}
publicvoid setItemsGroup(SelectItemGroup itemsGroup){
this.itemsGroup = itemsGroup;
}
public List getItemsList(){
return itemsList;
}
publicvoid setItemsList(List itemsList){
this.itemsList = itemsList;
}
publicvoid addNewItem(){
SelectItem item=new SelectItem(new Integer(itemsList.size()),newItem);
}
}
faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>bbean</managed-bean-name>
<managed-bean-class>backinbean.BackingBeanClass</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>

