0

I have a Check box group, whose values are computed by using the selected values of another Check box group. So when I do

var check6:com.ibm.xsp.component.xp.XspSelectManyCheckbox = getComponent("check6");
ArrSelected = check6.getSelectedValues();

to get the selected values, the following exception occurs:

Error calling method 'getSelectedValues()' on java class   'com.ibm.xsp.component.xp.XspSelectManyCheckbox'
java.util.ArrayList incompatible with [Ljava.lang.Object;

Check6 gets its values from a session scope variable that is computed on beforePageLoad event and I have also set the default value.

Note that this does not happen onload of the page, but when the first partial refresh happens. Does anyone know what this exception indicates?

Thanks a lot!

kmak
  • 63
  • 9
  • 1
    Please provide a some source code of the two components. – Sven Hasselbach Apr 17 '13 at 11:49
  • Are you using the variable `ArrSelected` in the check box group which is computed? If yes then how? You can compute the check box group simply using Add Formula Items, so your code would be something like `<![CDATA[#{javascript:getComponent("checkBoxGroup1").getSelectedValues();}]]>` (assuming original check box group name is `checkBoxGroup1`) and it would work. – Naveen Apr 17 '13 at 11:51
  • @Naveen Yes, I am using the values of checkBoxGroup1 as a key to get entries and then the corresponding documents from a view. And the value of checkBoxGroup2 is an array composed by the values of a particular field of the documents. Sven, I isolated these two lines of code and even if I add a print, the exception occurs again. – kmak Apr 17 '13 at 14:09

2 Answers2

1

Bind the value of the selectItems for the second check box group to precisely the same expression the first checkbox group's value attribute is bound to.

This article provides a lengthy description of the reason why, but here's a very quick summary: if you ask a component what its value is, it has to ask the data it's bound to. So skip the component, and ask the data yourself.

So, if your first group looks like this:

<xp:checkBoxGroup value="#{currentDocument.FirstField}">...

Then your second group should look like this:

<xp:checkBoxGroup value="#{currentDocument.SecondField}">
  <xp:selectItems value="#{currentDocument.FirstField}">
</xp:checkBoxGroup>

When the user's selection in the first group is posted to the data source, the second group will reflect the changes because they're linked to the same property on that data source. Slight caveat: if your page includes any required fields, you may need to skip validation on the onchange event that triggers the second group to recalculate.

Tim Tripcony
  • 8,056
  • 1
  • 23
  • 34
  • Thank you for your answer Tim. The thing is that the checkBoxGroups don't get their values from a document. The first one gets its values from a session scope variable, which gets its values from a view, and the second use the former values as key to get the entries of another view. – kmak Apr 17 '13 at 14:14
  • But regardless of how they get their select items, the user's selection is stored in data somewhere (document, scope, etc.). So the principle still applies: talk to the data, not to the component. Given your comment, I'm guessing you're using @DbLookup to get the second select item list. So just replace getComponent("check6").getSelectedValues() with an expression that references the data check6 is bound to, e.g. currentDocument.getValue("check6"), sessionScope.get("check6"), etc. So whatever the field is bound to, go there to get its value. – Tim Tripcony Apr 17 '13 at 14:48
  • Yes Tim, I read your article and get your point. But regardless the fact that going to the component and get its value is a bad practice, I believe that this doesn't explain the exception with function getSelectedValues() on a checkBoxGroup. – kmak Apr 19 '13 at 14:18
  • `XspSelectManyCheckbox` is a descendant class of `UISelectMany`. This is the class that defines the `getSelectedValues` method. This method simply calls `getValue()` and tries to cast it to `Object[]`. The error message you reported indicates that the actual value of the component is an instance of `ArrayList`, which cannot be cast to `Object[]`. – Tim Tripcony Apr 19 '13 at 14:49
-1

the reason is simple, this class has no method getSelectedValues() (as far as I can see it, look here for more info: http://public.dhe.ibm.com/software/dw/lotus/Domino-Designer/JavaDocs/XPagesExtAPI/8.5.2/index.html?overview-summary.html)

Maybe you could bind the control to a scoped variable and then access this variable to compute your other values?

  • 1
    Sorry Matthias, *XspSelectManyCheckbox* inherits this method from *javax.faces.component.UISelectMany* – Sven Hasselbach Apr 17 '13 at 11:30
  • @Matthias Nicklisch: The Java documentation link in your answer itself confirms Sven Hasselbach's comment. Here is the exact link: http://public.dhe.ibm.com/software/dw/lotus/Domino-Designer/JavaDocs/XPagesExtAPI/8.5.2/com/ibm/xsp/component/xp/XspSelectManyCheckbox.html#methods_inherited_from_class_javax.faces.component.UISelectMany – Naveen Apr 17 '13 at 11:56