Search code examples
xpagesxpages-extlibibm-sbt

How to access the raw JSON from a <xe:restJsonData> data Source


I'm successfully using a restJsonData source bound to a dataTable to display a list of projects

<xe:restJsonData var='rest' endpoint="myendpoint" serviceUrl="/projects/" paramCount="limit" paramFirst="offset" paramFirstType="page1" splitPath="items"> </xe:restJsonData>

To enable the users to filter I'd like to also have a combobox driven from the same response data. This initially sounded easy but building a combobox via a repeat control like this doesn't work..(comes out empty)

<xp:comboBox id="comboBox1"> <xp:repeat id="repeat1" rows="30" value="#{rest}" var="project" disableOutputTag="true"> <xp:selectItem itemLabel="#{project.fields[0].values[0].value}" itemValue="#{project.fields[0].values[0].value}"></xp:selectItem> </xp:repeat> </xp:comboBox>

So I believe I need iterate over the json manually and build a collection of selectitems. Fairly straightforward to do but first I need the raw json. I can get it like this..

@Endpoint("myendpoint").xhrGet("/projects/").getData();

but then I assume i'm calling the webservice twice.

so what I'd like to do is to get the raw json from the data source to avoid a 2nd call so I can iterate over it manually. Is that possible? myDs.getData() or something like that.

NB: I know longer term it would be better to do this with some beans however I want to see if it can be done quickly with the out of the box controls.

Thanks!


Solution

  • restJsonData caches the received data within a scope you defined. Therefore it's not a problem how many times you use the data source within the scope you have specified (request/view/session/application).

    In detail, restJsonData has a JsonAccessor which actually reads the data. That class (inherited from DataBlockAccessor) prefetches data and use it many times as long as we don't change parameters (e.g. page index, etc).

    Data is kept within a data container stored like a bean in scope variables. But I don't really know how to extract data from the data container.

    So it's a better idea to use additional repeat to construct your combobox. Your code seems OK, if you post json data structure, we can see if why it's not working.

    Additional note: Endpoint.xhrGet() is not cached.