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

selectOneMenu  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm working on an application (Address Database) using JSF (Base JSF libs with IBM Faces). Apache Tomcat Server 5.5.

Since days i'm trying to solve my problem with h:selectOneMenu and converter. I can save values correctly, but i cannot display the saved value again as a selected item.

so here is my jsf code section:
<h:selectOneMenu value="#{personBean.person.representative}"
styleClass="fldDefault fldcombo">
<f:selectItems value="#{partnerBean.representatives}" />
<f:converter converterId="keywordConvertor" />
<f:attribute name="SelectItemArrayList"
value="#{partnerBean.representatives}" />

representatives are keywords and in the selectOneMenu, a representative keyword object is stored.

here is my partnerBean.jsp Code:

private List<SelectItem> representatives = null;

* populate keywords of type REPRESENTATIVE
public void populateRepresentatives() {
representatives = new ArrayList<SelectItem>();
ArrayList<Keyword> representativeKeywords = kwHandler
for (Keyword keyword : representativeKeywords) {
representatives.add(new SelectItem(keyword, keyword

so the function gets the representative keyword objects, loop through them and add a newly created SelectItem Object to the representatives list.

There is a converter in order to save and display (should!!) the values:

public class KeywordConvertor implements Converter {

public Object getAsObject(FacesContext context, UIComponent component,
String value) {
....code for saving...

public String getAsString(FacesContext context, UIComponent component,
Object obj) {
`System.out.println(((Keyword) obj).getId()+"");
return ((Keyword) obj).getId()+"";

i did not provide the code for getAsObject, since the saving of the combo box works fine. If it has to do something with my problem, please ask me for this code..

The System.out.prinln prints all ids correctly, but the generated HTML Code does not select the given value in the combobox.

So whats wrong with the getAsString Method? or is the function completely somewhere else?
I have to say that the function ((Keyword) obj).getId() returns a long !! is that the problem?

Any help is very appreciated
Frederic Dehedin
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i know now where the problem is:

the value of person.getRepresentative function returns a keyword, when i printout the hashCode of the keyword object, i get e.g. 55336644

if i check the objects for the hashCode loaded in the SelectOne Combobox (printout in the KeywordConvertor.getAsString() method), i get a different hashCode for this selection!!! So there are two different objects and JSF doesn't recognise the selection of the different objects, although they have the same values.. is this correct?

By the way, we work with hibernate..

i tried also a function in the Keyword Class hashCode, which returns the id of the Database, in order to have the same ids in the objects, but no success

Anybody a solution?

If i don't find any, i forget working with objects in the selectOne Combobox but working with strings only, in the converter i get the keyword object again with the provided id. But if anyody has another solution, it would be very appreciated..
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!