Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

JSF drop down Converter issues

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"/>
</h:selectOneMenu>
. . . .

It is uses managed bean called TestBean.java:

public class TestBean {

public List getDeviceTypes(){
logger.info(" *** 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();
logger.info(" *** 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[]) it.next();
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)
logger.debug(o.toString());

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

}

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

Regards
Bansi
 
Shiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic