tags:

views:

4048

answers:

4

Hi

This should be easy for a pro:

I am using JSF/Facelets/Seam and am trying to display radiobuttons. Then, after the user has clicked on one of the buttons, the value should be saved and the user redirected to another page immediately (i.e. with no needed click on a submit button).

The radio button works, but not the forwarding.

Thanks

A: 

My mistake was elsewhere, this works nicely (f: being jsf, a: being richfaces):

<h:selectOneRadio id="anid" value="#{valueproperty}">
            <f:selectItem id="item1" itemLabel="foo" itemValue="foochoice"/>
            <f:selectItem id="item2" itemLabel="bar" itemValue="barchoice"/>
            <a:support event="onclick" actionListener="#{fooManager.actionMethod}"/>
</h:selectOneRadio>
A: 

Correction:

<a:support event="onclick" action="#{fooManager.actionMethod}"/>
Edit your first post, instead of creating a new one.
romaintaz
+2  A: 

You can indeed use Richfaces to add an a4j:support component:

<h:selectOneRadio value="#{myBean.myValue}" ...>
    ...
    <a4j:support event="onclick" action="#{myBean.doSomething}"/>
</h:selectOneRadio>

In your Java code:

public String doSomething() {
    // Your code goes here...
    ...
    // Now, we move to the new page.
    return "some-outcome";
}

However, if you cannot (or do not want) to add a new library, you can do this by the old way:

<h:selectOneRadio value="#{myBean.myValue}" ... onclick="this.form.submit();" valueChangeListener="#{myBean.doSomething}">
    ...
</h:selectOneRadio>

This code will submit the form where the radio button are contained when the onclick Javascript event is detected. On the server side, the action doSomething will be executed. In this method, you can make a navigation rule to be executed:

public void doSomething(ValueChangeEvent evt) {
    // Your code goes here...
    ...
    // Now, we move to another page...
    FacesContext context = FacesContext.getCurrentInstance();
    NavigationHandler navigation = context.getApplication().getNavigationHandler();
    navigation.handleNavigation(context, "", "some-outcome");
}

where some-outcome is an outcome defined in a navigation rule in your faces-config.xml.

romaintaz
A: 

How to read which radio button is clicked

Vikas
Please ask your own question by pressing "Ask Question" button at the top right instead of posting your question as if it's an answer by entering it in the "Your Answer" field. Please also elaborate the problem in a complete and clear manner; just an oneliner doesn't show any commitments and doesn't encourage others to help. Good luck.
BalusC