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



Aug 25, 2011, 1:38 PM
31 Posts

How can I get the javascript object for a REST service control ?

  • Category: Extension Library
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags:
  • Replies: 4
Hi all !
 
I'm using a REST service control.
 
Code:
                <xe:restService
                    id="restServiceMail"
                    jsId="jsRestServiceMail"
                >
                    <xe:this.service>
                        <xe:viewJsonService
                            defaultColumns="true"
                            var="entry"
                            viewName="xpMailByContactKey"
                        >
                            <xe:this.databaseName><![CDATA[#{javascript:applicationScope.get(applicationScope.Segment+"DOCCONTAINER")}]]></xe:this.databaseName>
                        </xe:viewJsonService>
                    </xe:this.service>
                </xe:restService>
 
Question:
How can I get a handle to the javascript object for this store ?
 
I've tried:

var storeID = "#{id:restServiceMail}";
var MailStore = dijit.byId(storeID);
//var MailStore = dojox.byId(storeID);
alert(MailStore.id);
 
But, I get MailStore is undefined... Any idea on how to get a handle to this object ? Maybe some casting is needed ?
 
When I get a handle to this store, I would like to reference this as the store in a dojox.grid.DataGrid (made by scripting).
 
Code:
<xp:scriptBlock id="scriptBlock1">
        <xp:this.value><![CDATA[               
       
        var MailStore = null;
        var grid = null;

                dojo.addOnLoad(function(){
                        var storeID = "#{id:restServiceMail}";
                       
                        MailStore = dojox.byId(storeID);
                   
                        alert(MailStore.id);
                         
                        var layout = [
                                { field: "icon", name: "icon" , width: "25px" },
                                { field: "Subject", name: "Subject", width: "350px", formatter: formatMailLink },
                                { field: "DocumentCategories", name: "Category", width: "400px" },
                                { field: "DocumentCategories", name: "Folder", width: "300px" },
                                { field: "Sent", name: "Sent / Recieved", width: "150px" },                                                               
                                { field: "Sent", name: "Sent by", width: "250px" }
                        ];
                       
                        function formatHTML(docUnid, rowIndex){
                                var linkVal = "<a href='PersonFormXPage.xsp?documentId=" + docUnid +"&action=openDocument'>link</a>";
                                return linkVal;
                        }
                       
                       
                        grid = new dojox.grid.DataGrid({
                                query: { Subject: '*' },
                                store: MailStore,
                                clientSort: true,                                 
                                autoHeight: 10,
                                autoWidth:true,
                                columnReordering: true,
                                noDataMessage: "<span class='dojoxGridNoData'>No data matched the query</span>",    
                                onRowDblClick: function(evt) {   
                                    var index = grid.selection.selectedIndex;
                                    var item = grid.getItem(index);
                                    var store = grid.store;
                                    var tmpUrl = "PersonFormXPage.xsp?documentId=" + store.getValue(item, 'docUnid') +"&action=openDocument";
                                                                                                         
                                       if (this.getItem(evt.rowIndex).locked != "true") {
                                          //alert(tmpUrl);
                                          window.document.location = tmpUrl;
                                       }
                                },                          
                                structure: layout
                        }, '#{id:gridNode}');
                                               
                        grid.startup();
                       
                });

      function Hello(){
      alert("Hello");
      }
     
]]></xp:this.value>
    </xp:scriptBlock>
 
 
Any tips would be greatly appreciated :-) Thanks !
 
regards,
Petter 
 
Sep 1, 2011, 1:52 AM
25 Posts
Re: How can I get the javascript object for a REST service control ?
 Petter,
 
 Well, I was thinking of an RPC service and actually replied with that information until I realized that was wrong. So.... the examples you showed should be able to find the REST service. You may want to try dojo.query to attempt to locate the object by trying:
 
var storeID = dojo.query("[id$='restServiceMail']");
var MailStore = dijit.byId(storeID[0].id);
 
and then use that storeID in your grid.
 
HTH 
Keith 
Sep 2, 2011, 12:41 PM
31 Posts
Re: How can I get the javascript object for a REST service control ?
Hi Keith,
 
I've now tried setting the store to both storeID and MailStore. 
 
No luck so far..
 
When using storeID I get: "this.store.getFeatures is not a function"
 Alerting storeID I get: view:_id1:_id44:pageTabContainer:tabContacts:_id45:_id112:detailsTabContainerContacts:djTabPanel11:restServiceMail
 
When using MailStore I get no error message, but it doesn't work..
Alerting MailStore I get: MailStore not defined.
 
My goal here is to be able to filter a grid (using a restService) client side without having to refresh the store/grid ?
I would like for the user to be able to select values from a drop down field, and have the grid filtered (by column value) on the selected values.
 
Any ideas ?
 
Thanks !
 
regards,
Petter 
 
 
Sep 2, 2011, 5:34 PM
25 Posts
Re: How can I get the javascript object for a REST service control ?
Petter,
 
As for requests to the store, have a look at this article for creating a Custom Query Store http://www.ibm.com/developerworks/web/library/wa-dojotreegrid/?ca=drs-  and I'm sure there are other examples out there I just know about this one off the top of my head. But according to your previous post I don't think you'll need to go this route.
 
Also, I've found that placement sometimes matters. In an attempt to replicate your issue I came across the same issue. Once I moved the REST service above the grid everything worked fine. 
 
The idea here is that as data is requested, an ajax request is sent to the server requesting the data, which is then sent back to the browser. When you make a request to the server, if you look in the FireBug Network console you should see a request that's the name of your xpage/restService name. Select that and look at the header to determine exactly what data is sent to the server and it's reply. It should reply with the JSON of whatever was requested. For example in the case of a grid, it should reply with the JSON of whatever view is being displayed. The entire view, search results, whatever should be represented in that JSON and that is what the content of the data grid will be.
 
But to address your issue of searching if you do a search for dojox.grid.DataGrid.filter you should find what you're looking for. I didn't have a chance to try and get that working.
 
HTH 
Sep 26, 2012, 9:15 AM
178 Posts
have you managed to find out howto get a hold on the rest service?

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