File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes problem with SelectOneListbox 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 "problem with SelectOneListbox" Watch "problem with SelectOneListbox" New topic
Author

problem with SelectOneListbox

Max Ji
Greenhorn

Joined: Mar 29, 2006
Posts: 12
Hello, am trying to create a SelectOneListbox and the page is giving this error which I can't decipher:

java.lang.IllegalArgumentException: Conversion Error setting value ''{0}'' for ''{1}''.
at com.sun.faces.util.Util.getSelectItems(Util.java:626)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getOptionNumber(MenuRenderer.java:461)
at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:438)
at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:406)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:713)
at javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:606)
at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:529)
at com.sun.faces.taglib.html_basic.SelectOneListboxTag.doEndTag(SelectOneListboxTag.java:489)
at jsp_servlet.__testselect._jspService(__testselect.java:189)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:214)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:120)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:272)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:165)
at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:504)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:245)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:142)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:214)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:120)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:272)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:165)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3022)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1925)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1848)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1288)

My code is below. I know someone posted a similar problem here recently but I can't figure out how he solved it. Thank you


testselect.jsp:

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
<head>
<title>A Simple JavaServer Faces Application</title>
</head>
<body>
<h:form>
<h:selectOneListbox value="#{form.languages}">
<f:selectItems value="#form.languageItems}" />
</h:selectOneListbox>
<h:commandButton value="Submit" action="listLanguage" />
</h:form>
</body>
</f:view>
</html>


RegisterForm.java:

package com.coversclasses;

import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.faces.model.SelectItem;

public class RegisterForm
{
private String language = null;

public String getLanguage()
{
return language;
}

public void setLanguage(String newValue)
{
language = newValue;
}

public SelectItem[] getLanguageItems()
{
return languageItems;
}

private static SelectItem[] languageItems = new SelectItem[] {
new SelectItem("en", "English"),
new SelectItem("fr", "French")
};
}


faces-config.xml:

<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>

<navigation-rule>
<navigation-case>
<from-outcome>listLanguage</from-outcome>
<to-view-id>/showLanguage.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<managed-bean>
<managed-bean-name>form</managed-bean-name>
<managed-bean-class>com.coversclasses.RegisterForm</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

<application>
<message-bundle>errorMessages</message-bundle>
</application>

<validator>
<validator-id>com.coversclasses.FileNbr</validator-id>
<validator-class>com.coversclasses.FileNbrValidator</validator-class>
</validator>
</faces-config>
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
selectOneListbox works as follows:

JSF

MyBean"value" can be of any object type and it must correspond with the selectedItem getter/setter. Usually it's just a String. "label" is what you see on the menu.
Max Ji
Greenhorn

Joined: Mar 29, 2006
Posts: 12
Hello Bauke Scholtz and thanks for the reply. I changed the code to match what you posted but the error is still appearing.


testselect.jsp:

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
<head>
<title>A Simple JavaServer Faces Application</title>
</head>
<body>
<h:form>
<h:selectOneListbox value="#{form.language}">
<f:selectItems value="#form.languages}" />
</h:selectOneListbox>
<h:commandButton value="Submit" action="listLanguage" />
</h:form>
</body>
</f:view>
</html>

RegisterForm.java:

public class RegisterForm
{

private String language;

private List languages;

public String getLanguage()
{
return language;
}

public void setLanguage(String newValue)
{
this.language = newValue;
}

public List getLanguages()
{
if (languages == null)
{
languages = new ArrayList();
languages.add(new SelectItem("en", "English"));
languages.add(new SelectItem("ch", "Chinese"));
}
return languages;
}
}
Max Ji
Greenhorn

Joined: Mar 29, 2006
Posts: 12
I found the problem. It was a typo in my page (left out the opening brace in my SelectOneListbox statement). Thank you again for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with SelectOneListbox