aspose file tools*
The moose likes JSF and the fly likes selectOneMenu and custom converter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "selectOneMenu and custom converter" Watch "selectOneMenu and custom converter" New topic
Author

selectOneMenu and custom converter

Henrique Sousa
Ranch Hand

Joined: Apr 29, 2004
Posts: 92
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<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
Henrique Sousa
Ranch Hand

Joined: Apr 29, 2004
Posts: 92
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

Joined: Nov 13, 2009
Posts: 3
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

Joined: Oct 23, 2007
Posts: 336

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="....">
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: selectOneMenu and custom converter