This discussion is archived
6 Replies Latest reply: Mar 26, 2013 5:13 AM by sarfraz RSS

checkbox valueChangeListener value

sarfraz Newbie
Currently Being Moderated
Hi guys,
I have a situation in which I have to render some components based on value of two checkboxes.I have called a function on value change of both checkbox using valuechangelistener.But the thing is that at a time I could get hold of value of only one checkbox.How can I get hold of both the checkboxes at the same time in my function.
  • 1. Re: checkbox valueChangeListener value
    826746 Newbie
    Currently Being Moderated
    Hi,

    can you try by getting hold of other checkbox either having a binding to backing bean or traversing the tree to get hold of second check box.


    Thanks,
    Naresh
  • 2. Re: checkbox valueChangeListener value
    adfLearner Explorer
    Currently Being Moderated
    In the valueChangeListener, you will get the value of the checkbox for which the value is called. You need to separately refer the value of second checkbox. Now accessing the value depends on how you have binded your checkbox -

    a) if your value is binded to bean variable, refer to that variable value.
    b) if it is binded to some VO attribute, refer to attributeBinding value using ADFUtil.getAttributeBinding("attrBindingName") --- Standard method to access attributeBinding value using bindings in ADF.



    Thanks,
    Rajdeep
  • 3. Re: checkbox valueChangeListener value
    911898 Newbie
    Currently Being Moderated
    Hi

    Can you please elaborate more on use case?

    If your checkbox value is coming from same VO, i am not sure why you want to have access to both at same time, but you can always set some count on number of checkboxes selected, by putting count in some viewScope or PageFlowScope, whatever you would like to use.
    Or just do setAttribute and check for checked ones.

    -Vineet
  • 4. Re: checkbox valueChangeListener value
    Puthanampatti Guru
    Currently Being Moderated
    try using js like,

    add clientListener to both check boxes...

    <af:clientListener type="valueChange"
    method="renderComponent"/>
    </af:selectBooleanCheckbox>


    <af:resource type="javascript">
    function renderComponent(event) {
    var source = event.getSource();
    if (source.getValue() == true) {
    var allVars = new Array("sbc1", "sbc2");
    for (i = 0; i &lt; allVars.length; i++) {
    var cb = source.findComponent(allVars);
    if (cb.getId() != source.getId()) {
    //do something.....
    }
    }
    }
    }
    </af:resource>
  • 5. Re: checkbox valueChangeListener value
    vikasadf Explorer
    Currently Being Moderated
    Hi Sarfraz,

    Please use same valuechangelistener for both checkbox components.
    It is already working for me and hope It will work for you.
    Like
    af:selectBooleanCheckbox text="selectBooleanCheckbox 1" label="Label 1" id="sbc1"
    valueChangeListener="#{test.chkchangeltsen}" autoSubmit="true"/>
    <af:selectBooleanCheckbox text="selectBooleanCheckbox 2" label="Label 2" id="sbc2" valueChangeListener="#{test.chkchangeltsen}"
    autoSubmit="true"/>

    Regards,
    Vikas

    Edited by: 812903 on Mar 24, 2013 11:57 PM

    Edited by: 812903 on Mar 24, 2013 11:58 PM
  • 6. Re: checkbox valueChangeListener value
    sarfraz Newbie
    Currently Being Moderated
    Thanku all guys..but I tried a much easier solution rather than javascript and bindings..I have made my variables static in the bean and individually getting the values for both the checkboxes...

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points