How to get itemValue of selected radio button in action of commandButton ?

I am new to JSFs and still learning the basics.

<html>

<head><title>Search by Catagory</title></head>

<body>

<h:form>

<h:selectOneRadio id = "searchCatagory" layout = "pageDirection" value = "#{SearchCatagory.searchCatagoryPage}" required = "true" onclick = "sameInfo()" >

<f:selectItem itemLabel = "Search for Cars" itemValue = "cars"/>

<f:selectItem itemLabel = "Search for Trucks" itemValue = "trucks"/>

</h:selectOneRadio>

<h:commandButton value = "Continue" action = "#{SearchCatagory.searchCatagoryPage}"/>

</h:form>

</body>

</html>

All these radio buttons and 'continue' button exist on the same page.

In this code i am trying to get the value of a selected radio button in the action parameter of commandButton.

So, for example, when i select 'Search for Cars' and click on the 'Continue' button it should take me to car.jsp. But, instead it gives this error message:

17:48:44,728 FATAL [application] org.apache.jasper.el.JspMethodNotFoundException: /jsp/SearchCatagoryPage.jsp(35,5) '#{SearchCatagory.searchCatagoryPage}' Method not found: gov.ca.ftb.accounts.SearchCatagory@151b1b7.searchCatagoryPage()

javax.faces.el.MethodNotFoundException: org.apache.jasper.el.JspMethodNotFoundException: /jsp/SearchCatagoryPage.jsp(35,5) '#{SearchCatagory.searchCatagoryPage}' Method not found: gov.ca.ftb.accounts.SearchCatagory@151b1b7.searchCatagoryPage()

I am using value = "#{SearchCatagory.searchCatagoryPage}" in the selectOneRadio, to initially set the default value. And that is working fine.

If i hard code the value like action = "cars" or action="trucks", then it works fine; It nevigates to the right page.

For some reason it doesnot like action = "#{SearchCatagory.searchCatagoryPage}" in commandButton.

Help please.

Thank you in advance.

[2005 byte] By [learningjava5a] at [2007-11-27 9:56:44]
# 1

You need to bind the value of selectOneRadio to the backing bean.

Basic example:

JSF<h:selectOneRadio value="#{myBean.selectedItem}">

<f:selectItem itemLabel="Search for Cars" itemValue="cars" />

<f:selectItem itemLabel="Search for Trucks" itemValue="trucks" />

</h:selectOneRadio>

<h:commandButton value="submit" action="#{myBean.action}" />

MyBeanprivate String selectedItem;

public void action() {

System.out.println(selectedItem);

}

public String getSelectedItem() {

return selectedItem;

}

public void setSelectedItem(String selectedItem) {

this.selectedItem = selectedItem;

}

BalusCa at 2007-7-13 0:26:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
You need to bind the action attribute of the button to a method in your backing bean not a property. The method should take no parameters and return String. The result is used as the outcome for navigation rules.
RaymondDeCampoa at 2007-7-13 0:26:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
You can indeed declare the return type as String and define a navigation case in the faces-config.xml. But if you declare it void, or let it return null, then it will issue a postback.
BalusCa at 2007-7-13 0:26:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Thank you for helping guys. I got it working now.
learningjava5a at 2007-7-13 0:26:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

> You can indeed declare the return type as String and

> define a navigation case in the faces-config.xml. But

> if you declare it void, or let it return null, then

> it will issue a postback.

BalusC, I was aware that you could return null, but are you certain about declaring void? I would be wary of that it sounds like something that might work in one implementation but not another. Section 7.3 of the 1.2 maintenance spec says that the method should return Object.

RaymondDeCampoa at 2007-7-13 0:26:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...