Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems using h:selectOneMenu

 
Jeremiah Lopez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been fighting JSF for a few days now on how to create a drop-down list based on static values. This will be a list where the user will only select one item. I'm getting exceptions when I navigate to the page that is using this control and I'm not exactly sure why, hence the reason for my post. These are JSF pages that are deployed in JBoss Portal 2.6.3.

In my faces-config.xml, I have the following entry:


Here is the CustomerBean class:


Here is where I'm setting up the component in the JSF file and referencing the CustomerBean:




And here's the lovely exception that I get once I navigate to the page:



That doesn't make any sense to me. I am explicity adding objects of type SelectItem to the list, so why would it say that objects are not of type SelectItem?

Thanks,
Jeremiah
[ March 30, 2008: Message edited by: Jeremiah Lopez ]
 
Alexander Bell
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i don't try that with an array of selectItems.

you can try to use a map (e.g. a HashMap) to deliver the values.
The keys are the lables on the HTML-Page an the values are the values for the bean-property.

You should also define the attribute "value" in the selectOneMenu-Tag.

mfg alex
 
Jeremiah Lopez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I figured that out yesterday. I tried using a Map and presto, it worked!
 
Jesus Carrillo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using a Map but still getting:

java.lang.IllegalArgumentException: Value binding of UISelectItems with component-path {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /pages/engineSeriesSearch.jsp][Class: javax.faces.component.html.HtmlForm,Id: _idJsp0][Class: javax.faces.component.html.HtmlSelectOneListbox,Id: engineSeriesNum][Class: javax.faces.component.UISelectItems,Id: availableEngines]} does not reference an Object of type SelectItem, SelectItem[], Collection or Map but of type : null

My JSP is:

<h:selectOneListbox id="engineSeriesNum">
<f:selectItems id="availableEngines"
value="#EngineSeriesSearchBean.engineSeriesValues}"/>
</h:selectOneListbox>

and code in my bean

public class EngineSeriesSearchBean
{
private Map<String,String> engineSeriesValues;

public EngineSeriesSearchBean(){}

public Map<String,String> getEngineSeriesValues()
{
Map<String,String> values = new HashMap<String,String>();
values.put("","");

for(int i=0; i<=5;i++)
{
values.put(String.valueOf(i), String.valueOf(i));
}
engineSeriesValues = values;
return engineSeriesValues;
}


public void setEngineSeriesValues(Map<String,String> values)
{
engineSeriesValues = values;
}
}

any idea of why Map didn't not work?
 
Qarabagi Jaan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a setter for the it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic