How to get a value of JSF selectBooleanCheckbox by using JavaScript? - Stack Overflow

I save in my selectBooleanCheckbox only boolean values in a backingbean which named "bean". T

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
Add a ment  | 

1 Answer 1

Reset to default 1

You 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;
 }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745617881a4636344.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信