selectOneListBox and validation error
Hi,
I have a validation error using a selectOneListbox. I read a lot of topics in this forum, but I still can't solve my pb.
This is my JSP:
<ice:selectOneListbox size="1" styleClass="totalWidth" value="#{controller.selectedCmsName}" >
<f:selectItems value="#{controller.cmsListItem}"/>
</ice:selectOneListbox>
This is the getter/setter for cmsListItem:
private List cmsListItem;
public List getCmsListItem()
{
cmsListItem =new ArrayList();
try{
cmsList =/* a method which returns an array */
for (int i = 0; i < cmsList.length; i++){
cmsListItem.add(new SelectItem(cmsList[i].getName(), cmsList[i].getName() +" (" + cmsList[i].getUsername() +")"));
}
}catch (Exception e){
}
return cmsListItem;
}
publicvoid setCmsListItem(List cmsListItem)
{
this.cmsListItem = cmsListItem;
}
Same thing for selectedCmsName:
private String selectedCmsName;
public String getSelectedCmsName()
{
return selectedCmsName;
}
publicvoid setSelectedCmsName(String selectedCmsName)
{
this.selectedCmsName = selectedCmsName;
}
There is a <h:messages/> tag in my jsp which give the message:
Validation Error
I don't see anything wrong in my code.... An idea?
Thanks,
phil
[2505 byte] By [
pippoua] at [2007-11-27 7:35:41]

# 5
Does it work with a real basic example?
test.jsp<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<html>
<head>
<title>test</title>
</head>
<body>
<h:form>
<h:selectOneListbox value="#{myBean.selectedItem}">
<f:selectItems value="#{myBean.selectItems}" />
</h:selectOneListbox>
<h:commandButton value="submit" action="#{myBean.action}" />
<h:outputText value="#{myBean.selectedItem}" />
<h:messages />
</h:form>
</body>
</html>
</f:view>
MyBeanpackage mypackage;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
public class MyBean {
private String selectedItem;
private List<SelectItem> selectItems;
{
selectItems = new ArrayList<SelectItem>();
selectItems.add(new SelectItem("value1", "label1"));
selectItems.add(new SelectItem("value2", "label2"));
selectItems.add(new SelectItem("value3", "label3"));
}
public void action() {
System.out.println(selectedItem);
}
public String getSelectedItem() {
return selectedItem;
}
public List<SelectItem> getSelectItems() {
return selectItems;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
}
}
Just copypaste it, add MyBean/myBean to the faces-config and execute it.
# 6
Hi,
I can't try your example since I use IcesFaces Ajax Framework, and a lot of changes would be necessary to run pure JSF example.
But I just tried ti replace
<f:selectItems value="#{cmsChoiceController.cmsListItem}"/>
by
<f:selectItem itemValue="black" itemLabel="Black"/>
and it worked...
I really don't understand.
Is there a way to know/display the object which makes the conversion error appear..?