Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

selectOneMenu and custom converter

 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yet another chapter in my battle against JSF. Now the subject is validation. I have a class like this:and I want to set that property from a set of AClass. So I create a method in my backing bean that creates that collection as an array of SelectItem:then a custom converter to deal with that array...All set, finally to the JSP:
All this went well for another class where I used a selectManyCheckbox. Beautiful. But now it gives me a "value is not a valid option" for that property. The method getAsObject from my converter is being called and returning an instance of AClass as expected, but still...

Any suggestions?
[ April 21, 2006: Message edited by: Henrique Sousa ]
 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I got a hint. Documentation does not say it is required to implement equals, but mine wasn't working correctly. Fixed equals() in AClass and everything works. My forehead is getting better now. Damn!
 
Silvana Donato
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An important point I'd like to point out for the future generations is that the selectOneMenu need to be fed up by an array of SelectItem and not a List as I tried and failed with

Something like this:

public SelectItem[] getAClassInstances() {
SelectItem[] selectItems;
//querying the db with hibernate query
Session sess = HibernateUtil.getSessionFactory().openSession();
Query query = sess.createQuery("from AClass");
selectItems = new SelectItem[query.list().size()];
int ii=0;
for(Iterator it=query.iterate();it.hasNext();){
AClassap = (AClass)it.next();
SelectItem item = new SelectItem(ap,
ap.getDescription(),
ap.getDescription());
selectItems[ii]=item;
ii++;
}
return selectItems;
}
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Silvana Donato wrote:An important point I'd like to point out for the future generations is that the selectOneMenu need to be fed up by an array of SelectItem and not a List as I tried and failed with

Something like this:

public SelectItem[] getAClassInstances() {
SelectItem[] selectItems;
//querying the db with hibernate query
Session sess = HibernateUtil.getSessionFactory().openSession();
Query query = sess.createQuery("from AClass");
selectItems = new SelectItem[query.list().size()];
int ii=0;
for(Iterator it=query.iterate();it.hasNext();){
AClassap = (AClass)it.next();
SelectItem item = new SelectItem(ap,
ap.getDescription(),
ap.getDescription());
selectItems[ii]=item;
ii++;
}
return selectItems;
}


Can you say why we can not use a list (java.util.List) ?

Actually I am using a List<SelectItem> to populate a <f:selectItems value="....">
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic