Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
530
radio button selection not getting submitted
posted

On my screens I have radio buttons and the selected value is not getting submitted when a command button is clicked. Here is one example:

 two radio buttons helping user to select whether it is public or provate. I know in this case a check box can serve the purpose and is a better choice. But this is how user wanted and screen is defined. Beside on other screen two radio buttons are needed to show selection.

 

Anyway, the tags are defined as folllowing:

<ig:radioButton id="qPrivateButton" styleClass="radioButton" label="Private" groupName="visibility"

value="#{myBean.privateSelected}"></ig:radioButton>

<ig:radioButton id="qPublicButton" styleClass="radioButton"

label="Public " groupName="visibility"

value="#{myBean.publicSelected}"></ig:radioButton>

 Where public/privateSelected are variables in bean defined of type boolean with appropraite accesssing methods. By defualt privateSelected is set to true and publicSelected to false. When I press say save button and control goes back the values of these variables are not updated.

When screen was initially rendering non of the radio button buttons was gettting selected. So I changed the tags to add checked attribute as following:

<ig:radioButton id="qPrivateButton" styleClass="radioButton"

label="My Query" groupName="visibility"

value="#{myBean.privateSelected}" checked="#{myBean.privateSelected}"></ig:radioButton>

<ig:radioButton id="qPublicButton" styleClass="radioButton" label="Public Query" groupName="visibility"

value="#{myBean.publicSelected}" checked="#{myBean.publicSelected}"></ig:radioButton>

 

after this change the initially the private radio button is selected as expected but the value is yet not getting changed if I cahnge my selection to public once the screen is rendered.

 Am I missing something here?\

***********************************************************************************************************************************************************

To try it in clean and simple files today I created the following code files and issue remains the same:

-----------------------------

test.jsp

----------------- 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>

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

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

<%@taglib uri="http://ko.infragistics.com/faces/netadvantage"

prefix="ig"%> <%@page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<link rel="stylesheet" type="text/css"

href="${pageContext.request.contextPath}/mpas/css/investments"

title="Style">

<link rel="stylesheet"

href="${pageContext.request.contextPath}/resources/infragistics/themes/investments/cna_investments.css"

type="text/css">

<link rel="stylesheet" type="text/css"

href="../../../theme/stylesheet.css" title="Style">

 

<f:view >

 

<h:form id="form1" styleClass="form">

<ig:radioButton id="radioButtonRenderer1" styleClass="radioButton" label="Button 1" groupName="bGroup" value="#{testBean.radioB1}" binding="#{testBean.radioB1Html}"></ig:radioButton>

<ig:radioButton id="radioButtonRenderer2" styleClass="radioButton" label="Button 2" groupName="bGroup" value="#{testBean.radioB2}" binding="#{testBean.radioB2Html}"></ig:radioButton>

 

<hr>

<h:commandButton type="submit" value="Submit" id="button1" styleClass="commandButton"

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

</h:form>

</f:view>

-----------------------------------

TestBean.java

------------------------------------

public class TestBean{

 

private boolean radioB1=false;

private boolean radioB2=true;

private HtmlRadioButton radioB1Html;private HtmlRadioButton radioB2Html;

 

public TestBean(){

super();CfLogWriter.debug("R");

}

 

public String submit()

{

setRadioB1(
radioB1Html.isChecked());

setRadioB2(radioB2Html.isChecked());

CfLogWriter.debug("radioB1: "+radioB1);

 

CfLogWriter.debug(
"radioB2: "+radioB2);return "success";

}

 

 

 

public boolean isRadioB2() {return radioB2;

}

 

 

public void setRadioB2(boolean radioB2) {this.radioB2 = radioB2;

}

 

 

public boolean isRadioB1() {return radioB1;

}

 

 

public void setRadioB1(boolean radioB1) {this.radioB1 = radioB1;

}

 

public HtmlRadioButton getRadioB1Html() {

// if (radioB1Html!=null && radioB1Html.isChecked()==null)

// (radioB1Html.setChecked(radioB1))

return radioB1Html;

}

 

public void setRadioB1Html(HtmlRadioButton radioB1Html) {this.radioB1Html = radioB1Html;

}

 

public HtmlRadioButton getRadioB2Html() {return radioB2Html;

}

 

public void setRadioB2Html(HtmlRadioButton radioB2Html) {

// if (radioB2Html!=null && radioB2Html.isChecked()==null)

// {}

this.radioB2Html = radioB2Html;

}

----------------------------------

 If I use checked="true" attribute, in the tag , when page it displayed the radio button is checked otherwise it doesn't matter whether radioB1 or radioB2 is initially set to true or false. None of the button shows being checked.

Then I click on button 1 and submit the button in bean both get value os false. radioB2Html variables show checked null in debug mode and when I use radioB2Html.isChecked() it returns false for both buttons.

After submit action method when page is displayed again of course both buttons show not checked.

I initially tried this code without binding to radioB2Html variables that didn't worked either.

-----------------------------------------------------------------------------------------------------------------------------------------

If I add value change listener for both buttons and set immediate to true for both, in both value change listeners new and old values are false.