Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create a Different selectOneListbox Depending On the Radio Button Clicked

 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to prompt a specific selectOneListbox depending on the radio button that the user clicks?

I have created a set of radio buttons:

The code in my jsp page is like:

and I know how to create selectOneListbox.

But, I am having problem to prompt different list of records depending on the radion button on which the user clicks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a value change event for each radio button, give your private SelectItem[] records a different set of SelectItems[].
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply; but, huh? I do not understand.

I have a listbox A created:

I have another listbox B.

I have two radio buttons. The default radio button displays the listbox A. If user click on the other radio button, the browser is supposed to diaplay listbox B.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohh, ok, so you need a boolean member in your backing bean and use the rendered attribute for your listboxes that is based on that boolean value.

rendered="#{dataManagementBean.showListOne}"
rendered="#{!dataManagementBean.showListOne}"
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I am even more confused.

I have two radio buttons; one is default and the other is not default. the radio buttons are created this way:

where defaultSelectedRecord and records are the properties in my backing bean: DataManagementBean.

When my web page is first displayed, the defaultSelectedRecord is selected, and the list box A is supposed to be on the screen.

If users opt for the other radio button, I am supposed to prompt list box B on the screen.
[ September 21, 2005: Message edited by: Daniel Gee ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a change listener for your radio buttons?
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have put a ValueChangeListener for my radio button. I have two radio buttons. And I have two list boxes. List box A will be displayed if the first radio button is clicked by users. List box B will be displayed if the second radio button is clicked by users.

To have something displayed in the list box when the web page is "first" rendered, I would like to show a default radio button (the first radio button) and display the list box A.

But, my code has a "runtime" error:

java.lang.IllegalArgumentException: Conversion Error setting value ''{0}'' for ''{1}''.


My code is show below. In my jsp page, I try to construct a set of radio buttons and a list box:

In my backing bean, I have:

This is how I contruct my "records", which is a Map:

The runtime error message is:

java.lang.IllegalArgumentException: Conversion Error setting value ''{0}'' for ''{1}''.
com.sun.faces.util.Util.getSelectItems(Util.java:628)
com.sun.faces.renderkit.html_basic.MenuRenderer.getOptionNumber(MenuRenderer.java:488)
com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:465)
com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:430)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:720)
javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:623)
javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:546)
com.sun.faces.taglib.html_basic.SelectOneListboxTag.doEndTag(SelectOneListboxTag.java:521)
org.apache.jsp.pages.screen1_jsp._jspx_meth_h_selectOneListbox_0(screen1_jsp.java:383)
org.apache.jsp.pages.screen1_jsp._jspx_meth_h_form_0(screen1_jsp.java:212)
org.apache.jsp.pages.screen1_jsp._jspx_meth_f_view_0(screen1_jsp.java:164)
org.apache.jsp.pages.screen1_jsp._jspService(screen1_jsp.java:129)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me answer my own question.

Take a look at the example provided by Richard Hightower at http://www-128.ibm.com/developerworks/java/library/j-jsf2/
 
vasavi devi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
in the jsp page you have given something like this.

<h:selectOneRadio value="#{dataManagementBean.dataTransferTypeItems[0]}" layout="pageDirection" onchange="submit()" immediate="true" valueChangeListener="#{dataManagementBean.showRecordList}"><f:selectItems value="#{dataManagementBean.dataTransferTypeItems}"/></h:selectOneRadio>

remove "[0]" while giving the value.
value="#{dataManagementBean.dataTransferTypeItems}"

try to give like this and try.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem was more complicated than that.

I have had it worked out. I followed the example provided by Richard Hightower at http://www-128.ibm.com/developerworks/java/library/j-jsf2/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic