2

I have created an Xpage with only one element, a JSON Rest service that points to a view (I guess I should probably put this in a CC).

I want to build another Xpage with a CC that contains a CC that contains a Dojo Data Grid that points to this rest service.

How can I do that? It seems to me that I should separate out my calls to the data from the interface. I am surprised that this is not easier to do.

Bryan Schmiedeler
  • 2,977
  • 6
  • 35
  • 74

2 Answers2

3

As Knut mentioned, the xp:include tag (the Include Page control) seems to be the easiest solution.

You don't have to move the REST service to a custom control, though. You can just include the page with the REST service on the same page that contains your grid custom control (or on the grid custom control itself).

Then, in the grid's storeComponentId property of the grid control, you can specify the ID of the REST service and the server will be able to resolve it.

  • These are all good suggestions. My company is going big with Rest Services. I think they are great because we have so much duplicated data, and we are going to dedup and use Rest Services to provide the data to a variety of applications to consume it. Given that I wondered if it would be best to put our Rest services in on DB. I believe I can get data from a view on a different DB, but can I consume the data if the rest service is in a central repository. [Love your blog by the way] – Bryan Schmiedeler Jun 11 '14 at 18:07
  • With any pure client-side JavaScript grid (including a Dojo grid not using the XPages Dojo Data Grid control), you can get data from a remote source via a URL, which would allow you to refer to REST services in a central database. However, I'm not aware of a way to make that happen easily with the Dojo Data Grid control. I just ran some tests to try to compute the Include Page control to refer to a page outside of the current database, but I was not successful... – Brad Balassaitis Jun 11 '14 at 18:58
  • ...Instead of using the storeComponentId property, you could use the store property of the grid control. You should be able to load remote data into a client-side JavaScript variable and use that for your grid data source. (I haven't tried it with remote data, but that's conceptually what it's for.) You'd have to test to see how well it handled scrolling, etc. You may need to make the remote request to load the full data set. – Brad Balassaitis Jun 11 '14 at 19:00
  • Brad, thanks so much. I am going to have to digest all that you and Knut have told me. But it looks like this is the way to go. – Bryan Schmiedeler Jun 12 '14 at 14:11
2

Put your REST service in a CC and include it into your Dojo Data Grid control XPages/CC.

<xp:include
       id="restService"
       pageName="restServiceCC.xsp" />

Don't forget to add ".xsp" to the name of your CC.

Update

To use include is the (only) way to separate the Dojo Data Grid control and the REST service in separate XPages/CC as you asked in your question.

As REST services can be separate design elements this way you can define all REST services in a template database and let the applications inherit from there. REST services itself can provide data from any database/view.

The Dojo Data Grid control is the easiest way to include Data Grids to your applications but it needs the REST service to be in the database itself.

As an alternative you can use a "pure" Data Grid based on client side JavaScript. Data Grids get their data usually from an URL per Ajax. This would give you the possibility to put all REST services in one database. You have much more flexibility with this approach than using the Dojo Data Grid control. But, be aware that it needs some days to get into it. I use the free jqGrid based on jQuery as the "pure" Data Grid. You can find more information about it in my presentation at EntwicklerCamp 2014 (sorry, its in German - Google translator is your friend) including a comparison with Dojo Data Grid and ExtJs Grid.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Knut, this is awesome. I really like the idea of putting all rest services in one template and inherit from it. I went through Brad's Dojo Data Grid tutorials expecting that categorization would come up, but toward the end he said that you had to use a custom Dojo Data grid. I will check out your presentation and the jqGrid. Thanks! – Bryan Schmiedeler Jun 12 '14 at 14:06