admin管理员组文章数量:1435859
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;
}
本文标签: How to get a value of JSF selectBooleanCheckbox by using JavaScriptStack Overflow
版权声明:本文标题:How to get a value of JSF selectBooleanCheckbox by using JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745617880a2666509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论