Show/hide text box on check/uncheck of a checkbox in richfaces 4
I was working in Richfaces 4 where i had a requirement that, there's a checkbox & if someone checks it, the boolean value should be stored in a boolean variable in the backing bean without the form being submitted. And according to the value of that variable in backing bean, a text box should be rendered. The coding is somewhat like this:-
<h:selectBooleanCheckbox id="test" onclick="jsRender()" onchange="document.getElementById('formName:test').checked == true ? #{bean.setChecked(true)} : #{bean.setChecked(false)}" />
<a4j:jsFunction name="jsRender" render="@form" />
<h:inputText id="textBox" value="bean.Something" rendered="#{bean.checked}"/>
As far as I know, until the form is submitted, the value of checkbox is not stored in the backing bean. But since I need it to change before Form submission, I have used that condition in the 'onchange' attribute. But the problem is that, the ternary condition is not getting executed, only the el expressions are executing, so I am getting a true as well false no matter if i 'check' or 'uncheck'. I think the syntax is wrong. I need help with the correct syntax.
Thanks in advance :)
To solve this issue I used something like this :-
<selectBooleanCheckbox id="test" value="bean.something">
<a4j:ajax event="change" render="div_name" execute="@this">
</selectBooleanCheckbox>
And this solution worked for me.
链接地址: http://www.djcxy.com/p/88846.html