This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Mar 30, 2011, 11:29 PM
29 Posts

getting selected documents on a repeat control

  • Category: Other
  • Platform: All
  • Release: 8.5.2
  • Role:
  • Tags:
  • Replies: 9
I was hoping someone could point me to a doc on how to do this.
 
1. I've made a repeat control and want to have check boxes on each row.
2. User selects the documents they want to update, selects a value from a drop down box and clicks an update button.
 
I found this example but brings up an error when I change it to repeat1 from viewpanel1

var viewPanel=getComponent("repeat1");
var docIDArray=viewPanel.getSelectedIds();
for(i=0;
i < docIDArray.length;
i++){
var docId=docIDArray[i];
var doc=database.getDocumentByID(docId);
doc.status="test"
doc.save(true)
}
 
I've searched everywhere for example, surely this is something nearly all new users want to do, why is it so hard to find examples?
Mar 31, 2011, 9:31 AM
261 Posts
Re: getting selected documents on a repeat control
Hi,
 
getSelectedIds only works on a view panel, not in a repeat control. In a repeat control you can bind a checkboxes to a viewScope variable.

The trick to it is that you first fill the viewScope variable with a blank array with the same number of items than the repeat control. You then bind a checkbox to an indexed item of that array.
 
Copy the following code to a new blank XPage to see a sample:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
   
    <xp:this.afterPageLoad><![CDATA[#{javascript:var numEntries = getComponent("repeat1").getRowCount();
viewScope.put("selectedIds", new Array(numEntries) );}]]></xp:this.afterPageLoad>
    <xp:repeat id="repeat1" rows="30" var="dataItem"
        indexVar="dataIndex">
        <xp:this.value><![CDATA[#{javascript:[
 {name: "item 1", id: "id1"},
 {name: "item 2", id: "id2"},
 {name: "item 3", id: "id3"},
 {name: "item 4", id: "id4"}
]}]]></xp:this.value>
        <xp:checkBox id="checkBox1"
            checkedValue="#{javascript:dataItem.id}" uncheckedValue="">
            <xp:this.value><![CDATA[#{viewScope.selectedIds[dataIndex]}]]></xp:this.value>
        </xp:checkBox>
        <xp:text escape="true" id="cfName"
            value="#{javascript:dataItem.name}">
        </xp:text>
        <xp:br></xp:br>
    </xp:repeat>
    <xp:br></xp:br>
    <xp:button value="Show selected" id="button1">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="partial" refreshId="cfSelectedIds">
        </xp:eventHandler></xp:button>
    <xp:br></xp:br>
    <xp:br></xp:br>You've selected:&#160;
    <xp:text escape="true" id="cfSelectedIds"
        value="#{javascript:@Trim(viewScope.selectedIds)}">
    </xp:text></xp:view>

 
 
Mar 31, 2011, 6:09 PM
586 Posts
Re: getting selected documents on a repeat control
Mark,
 
In the example I did I used java.util.ListArray I think.  So there no need to know the total count of the repeat control.  It's more like a list where you can just add as needed. 

Not sure which way is better - just wanted to mention it to you.
 
Dave
Apr 1, 2011, 8:46 AM
261 Posts
Re: getting selected documents on a repeat control
Dave,
 
I had at look at the demo you created: your and my alternative both eventually do the same. They offer a way to store/retrieve a list of selected rows (when not using a view control) in a server variable.

The main difference is that in your demo a server-call is made on every click of the "Add" button. In that call an ID of the clicked row is added to the a viewScope (array) variable.

In my sample I've bound the checkboxes directly to a viewScope variable (that's why I have to create an array containing a specified number of items before the page is rendered). This doesn't require a server-call for every checkbox tick/ untick: it send the selected items to the server when the "Show selected" button is clicked. For an end user this works/ looks the same as offering default checkboxes in a viewPanel.
 
Cheers,
Mark
 
 
Apr 1, 2011, 9:12 PM
586 Posts
Re: getting selected documents on a repeat control
Interesting.  Thanks for pointing out the difference to me.  I knew I was generating server calls on each button.  I didn't realize yours was more done as a batch.
 
thanks!
Jun 17, 2011, 9:02 AM
2 Posts
Re: getting selected documents on a repeat control
Mark
 
I have used your method to get checkboxes in a repeat and it works great.  Do you know how you would go about adding a 'Select All' checkbox that ticked all the checkboxes?
Jun 17, 2011, 1:27 PM
261 Posts
Re: getting selected documents on a repeat control
Ed,
 
You could do that in a number of ways.

If all your entries are on one page, you could add a clientside script to the button that checks all the boxes. Using dojo that could be something like (not tested btw):
 
dojo.query("input[type=checkbox]", "#{id:yourViewControlId}").forEach( function(checkbox) { checkbox.checked = true;} );
 
Another approach would be to call a serverside script that fills the selectedIds viewScope variables with all the ID's of the items in the repeat (in the same order !).

Mark
Mar 31, 2011, 6:03 PM
586 Posts
Re: getting selected documents on a repeat control
Basically you want to do a getSelectidIDs but with a repeat control and not a view panel right?
 
I've done this.  It's on my short list for a NotesIn9 episode but I've not recorded it yet.  There is an example in the demo app on http://xpagescheatsheet.com

Click on "Picking Rows" on the left.  You can download the the example and pick it apart, or wait for the NotesIn9 show...
 
hope that helps

Dave
Apr 1, 2011, 4:01 AM
29 Posts
Re: getting selected documents on a repeat control
David,
 
Checked out your example, exactly what I need. I'll download it and have a go..
 
BTW the support on this site is great... and Xpages seems to answer all my clunkiness issues.. let's hope it takes off..
Apr 5, 2011, 12:51 PM
4 Posts
Re: getting selected documents on a repeat control
This example is already old, but may be should help:
 
http://iqjam.net/iqjam/iqjam.nsf/questions/20100319_Checkbox_in_repeater_as_%22Selec.htm

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal