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 31, 2011, 9:31 AM
261 Posts

Re: getting selected documents on a repeat control

  • Category: Other
  • Platform: All
  • Release: 8.5.2
  • Role:
  • Tags:
  • Replies: 9
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

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