XPages question: How to set a value for a checkbox group based on condition?

I would like to set a value for a checkbox group when clicking on a link.

In the example below you see a table on the right. The icons in the header reflect values in check box groups on the left.

I think it will be more easy to understand for users when they could also click the icons. Eventually I could hide the checkboxes in a later stage…

Getting the values of a checkbox is not so hard:

var component=getComponent(“nameOfCheckBoxGroup”).getAttributes().get(“value”);

But untill now I have not found a working example how to set values based upon the condition that a check box group does not has the value. Server-side JavaScript is not my thing right.

Setting the values should be done according the following method (I guess):

getComponent(“checkboxID”).getAttributes().put(“value”,arrayofvalues);

 

Advertisements

12 thoughts on “XPages question: How to set a value for a checkbox group based on condition?

  1. Matt White 2010-October-11 / 4:24 pm

    Rather than manually getting and setting the control directly, another approach may be to bind the control to a scoped variable (viewScope probably) and then changing the value that way instead.

    Matt

    • Patrick Kwinten 2010-October-11 / 4:44 pm

      Hmm I have quiet a lot of checkbox groups, setting each control directly would be easier seems to me…

  2. Jeremy Hodge 2010-October-11 / 5:23 pm

    Why do it server side? From the screen shot I am assuming this is on one page, in which case you can just set the value of the checkbox field client side … Then you do not have to round-trip anything …

    • Patrick Kwinten 2010-October-12 / 1:48 pm

      Well there are some on changes events bound to the checkboxes that use server side js, accessing the checkboxes via the DOM is a bit harder since there are no ID assigned to the elements 😕

  3. Tim Tripcony 2010-October-11 / 5:28 pm

    The server-side equivalent of what Jeremy’s suggesting is:

    getComponent(“checkboxID”).getValueBinding(“value”).setValue(arrayofvalues);

    Regardless of whether the checkbox group is bound to a scoped variable or a form item (or anything else, such as a property of a managed bean), the above code is a generic way of calling the corresponding setter.

    • Patrick Kwinten 2010-October-12 / 2:04 pm

      Hej Tim,

      I was thinking as followed:

      var vb = getComponent(“filtersecurity”).getValueBinding(“value”)
      vb.setValue(facesContext,”Encryption”);

      or

      getComponent(“filtersecurity”).getValueBinding(“value”).setValue(facesContext,”Encryption”);

      however I get a runtime error saying: ‘vb’ is null / ‘getComponent().getValueBinding()’ is null

      When I use
      var component=getComponent(“filtersecurity”).getAttributes().get(“value”);

      I have no problems accessing the checkbox group. What can be the cause getValueBinding(“value”) method causes the error?

      • Praveen Pulla 2011-January-25 / 4:37 pm

        Hi,

        I tried getting the value of the checkbox and it works fine….Thanks for the info provided .
        I need to set the checkbox to checked for few values in the onload of the form itself.
        Ex : If I have 2 states(Virginia,MI) with checkboxes. I need to put a tickmark for Virginia when the user clicks on a button.

        How do I do that?

        Thanks in advance for your help…

        Praveen

  4. Mervin 2010-November-2 / 10:09 pm

    Thanks Pat.. This was eating my head for 3,4 days. This was perfect. Super. Thanks very much.

  5. Praveen Pulla 2011-January-25 / 11:09 pm

    Hi,

    I got the solution…

    Example:
    var valArr1 = new Array();
    valArr1[0] = “1”
    valArr1[1] = “2”
    valArr1[2] = “3”
    valArr1[3] = “4”
    getComponent(“checkBoxGroup1”).getAttributes().put(“value”,valArr1);

    This will put the check the checkboxes on an event…

  6. Bill Hanson 2011-September-27 / 10:42 pm

    You all probably already know this, but as of 8.5.2 (i think), the getComponent().setValue and getComponent().getValue methods work as expected.

    • Sameer B 2012-December-6 / 11:20 am

      getComponent(“checkBoxGroup1”).getValue() is not working for checkBoxGroup….
      Please Help….

  7. Smith 2013-January-24 / 12:59 am

    I am using checkbox group in xpages and the checkbox group value is computed. I tried all the above methods to retrieve the checked values from checkbox but nothing worked. I used the folowing method : getComponent(“Checkboxlist”).getAttributes().values() and it returns empty array. Anyone has any better ideas ? Please help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s