myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bansi <>
Subject JSF Dropdown Converter Issues
Date Wed, 10 Jan 2007 23:36:23 GMT

I am having problems with JSF 1.1_01 (MyFaces 1.1.1). 

I have created page called page.jsp as follows:

. . . .

<h:selectOneMenu value="#{test.selectedDevice}" id="deviceTypeList"
<f:selectItems value="#{test.deviceTypes}" />

<ajax:support action="#{test.loadDevice}" event="onchange"
. . . .

It is uses managed bean called

public class TestBean {

public List getDeviceTypes(){" *** In getDeviceTypes Backing Bean*** ");
List<SelectItem> models = new ArrayList<SelectItem>();
List<SelectItem> deviceTypes = new ArrayList<SelectItem>();
// Gets Data from Hibernate Query . It returns List of Device Types
models = deviceManager.getDeviceTypes();" *** DeviceType List Size=*** "+models.size());

for (Iterator it = models.iterator(); it.hasNext();) {
System.out.println("Inside For Loop Iterator size="+models.size());
Object[] row = (Object[]);
System.out.println("ID: " + row[0]); // prints data
System.out.println("Name: " + row[1]); //prints data
// Below line results in error : does not have a Converter
deviceTypes.add(new SelectItem(row[0],row[1]+"")); 

return deviceTypes;


During page rendering, page.jsp throws following exception:
javax.servlet.ServletException: Value is no String and component
_id0:deviceTypeList does not have a Converter

Is this bug with MyFaces 1.1.1 or I have made something wrong?

I am a newbie & didnt know much about Converters hence read some examples
from the web stating to have getObject() & getString methods . So i added
below Class but not sure how to align with page.jsp page.
public class DeviceTypeConverter implements Converter{
protected final Log logger = LogFactory.getLog(getClass());
public Object getAsObject(FacesContext facesContext, UIComponent
uiComponent, String s) throws ConverterException {
DeviceDao dao = new DeviceDao();
return dao.getdeviceTypes().(Long.decode(s));

public String getAsString(FacesContext facesContext, UIComponent
uiComponent, Object o) throws ConverterException {

if(o!= null)

try {
if((o!= null) && (o instanceof DeviceType)){
DeviceType dt = (DeviceType) o;
return ""+dt.getId();
return "0";
} catch (Exception e) {
throw new ConverterException();


Any pointers/suggestions on how to write a Converter & help in resolving the
error will be highly appreciated

View this message in context:
Sent from the MyFaces - Users mailing list archive at

View raw message