I save in my selectBooleanCheckbox only boolean values in a backingbean which named "bean". To set a label for this checkbox in my JSF xhtml page i´m using a JSF outputText ponent.
Here is the JSF code (they are 2 checkboxes in this example):
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue1}" />
<h:outputText value="My Labeltext1"/>
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue2}" />
<h:outputText value="My Labeltext2"/>
Now i want to get the selected checkboxes with java script. I´m using the onselect event:
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue1}" onselect="MyObject.update(this.options[this.selectedIndex].text);"/>
<h:outputText value="My Labeltext1"/>
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue2}" onselect="MyObject.update(this.options[this.selectedIndex].text);"/>
<h:outputText value="My Labeltext2"/>
But this gets only the boolean values of the selected checkboxes. Is it possible to get the value of the outputText ponents? Is tehre any way to connect the output ponent with the selectBooleanCheckbox ponent?
I save in my selectBooleanCheckbox only boolean values in a backingbean which named "bean". To set a label for this checkbox in my JSF xhtml page i´m using a JSF outputText ponent.
Here is the JSF code (they are 2 checkboxes in this example):
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue1}" />
<h:outputText value="My Labeltext1"/>
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue2}" />
<h:outputText value="My Labeltext2"/>
Now i want to get the selected checkboxes with java script. I´m using the onselect event:
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue1}" onselect="MyObject.update(this.options[this.selectedIndex].text);"/>
<h:outputText value="My Labeltext1"/>
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue2}" onselect="MyObject.update(this.options[this.selectedIndex].text);"/>
<h:outputText value="My Labeltext2"/>
But this gets only the boolean values of the selected checkboxes. Is it possible to get the value of the outputText ponents? Is tehre any way to connect the output ponent with the selectBooleanCheckbox ponent?
Share Improve this question asked Jan 17, 2014 at 10:07 user2504767user2504767 1-
2
I'm not sure about the hard part. JSF is just a HTML code generator and JavaScript just works on the JSF-generated HTML DOM tree. When writing JavaScript code, don't look at JSF source code, but instead at its generated HTML output (as you can find by rightclick, View Source in browser). It look like that you're unnecessarily focusing way too much on JSF source code while attempting to write JS code for the job. Continuing that, you'll get faster answers from
[javascript]
experts when you reframe your question to replace JSF source code by its generated HTML output. – BalusC Commented Jan 17, 2014 at 11:02
1 Answer
Reset to default 1You should give a unique ID to the ponents and then try getting these values in java script by their ID , Also you can use 'onclick' to call the java script method. for ex:
<h:selectBooleanCheckbox id="firstBox" class="extern" value="#{bean.booleanValue1}" onclick="update(this)"/>
<h:outputText id="firstOutput" value="My Labeltext1"/>
And your java script function would look something like this:
function update(val){
var box= document.getElementById("firstBox");
var outPut = document.getElementById("firstOutput");
var boxValue = box.value;
var outPutValue = outPut.value;
}