• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

problem with SelectOneListbox

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic