Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF drop down Converter issues  RSS feed

Bansilal Haudakari
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" styleClass="dropdown">
<f:selectItems value="#{test.deviceTypes}" />

<ajax:support action="#{test.loadDevice}" event="onchange" reRender="t2,t3,t4,t5"/>
. . . .

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

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!