LiveTable query parameters

Hello,

I have two Classes.

ClassOne with data and ClassTwo with data. ClassTwo has a multiple select database list consisting of ClassOne ID’s.

Our Classes have generated ID’s that correspond with their page ID’s. (idString)

So ClassTwo.usesClassOneRecords can contain ID1, ID2, ID4

I want to populate a livetable of ClassOne where ID in ClassTwo.usesClassOneRecords. (ID1,ID2,ID4)
I got $searchVar filled with the right ID’s and want to pass them to the livetable.

I used “extraParams” : “&idString=$searchVar” and “extraParams” : “&idString in $searchVar”

But both do not work. Is there a way to get this working as if it was a select * from ClassOne where idString IN ($searchvar)

Thanks in advance
Jurjen

Hi Jurjen,

I think this answer https://forum.xwiki.org/t/merging-2-or-more-classes-into-1-livetable/5561/2?u=oana-lavinia_florean should be helpful in your case as well (i.e. using that page to apply your filter).

Thanks,
Lavinia

Thank you Oana,

I have made an JSON but I have no results yet.

I have two questions.

  1. I have a variable I want to pass to the query in the JSON, how do you do this?
  2. How do I see if the livetable actually gets the JSON. If I test the JSON with the variable set in the velocity code, I get a JSON file. But I do not get the results in the livetable

Thanks
Jurjen

  1. I have a variable I want to pass to the query in the JSON, how do you do this?

You can use bindValue like in this example https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module#HFindingpagesundernestedpages

  1. How do I see if the livetable actually gets the JSON. If I test the JSON with the variable set in the velocity code, I get a JSON file. But I do not get the results in the livetable

You can follow it using Network tab by selecting the request to you page that contains the JSON. There you will see what exactly is the result. Also, if there are other results beside the json (if you put something for debug purposes), the livetable will just be empty.

Hope it’s helpful,
Lavinia

Hi Oana,

Thank you. It helped.

I used the example code, modified it a bit, to get the right data.

What I see is a request with a /bin/get/JSON. It gives an empty page. The same request with /bin/view/JSON gives the JSON (with the XWIKI format of pages).

Any ideas where I should search to fix that.

Hi,

Maybe your page is actually called “JSON.WebHome” and you didn’t added it correctly in the resultPage attribute? In view mode is not necessarily to add it to the url.
Also, you could check to output the json only on a get request #if ($xcontext.action == 'get') .. #end .

Hi Oana,

I think I am very close, but I don’t get it. I have two questions

  1. Why do I not get a valid JSON response?

  2. How do I pass a custom variable to the call of the JSON. I have a variable I bind in the query. But how do I get it in the request string?

  3. The page is RapJSON in GeneriekeKlassen. If I call it with trailing / I get results, but escaped. Without I get a blank page.

http://dev.wiki:8080/bin/get/GeneriekeKlassen/RapJSON/?reqNo=1

Gives the following result:

<p>&#123;"totalrows":2,"matchingtags":&#123;},"tags":[],"returnedrows":2,"offset":1,"reqNo":1,"rows":[&#123;"doc_viewable":true,"afkorting":"Test","naam":"Test","korteOmschrijving":"Test","PrivacyGevoelig":""},&#123;"doc_viewable":true,"afkorting":"Test2","naam":"Test2","korteOmschrijving":"Test2","PrivacyGevoelig":""}]}</p>

dev.wiki:8080/bin/get/GeneriekeKlassen/RapJSON?reqNo=1

Gives a blank page.

The URL calling the livetable which I see in the Network Tab of the browser =

http://dev.wiki:8080/bin/get/GeneriekeKlassen/RapJSON?outputSyntax=plain&transprefix=GeneriekeKlassen.DatasetClass_LT_&classname=GeneriekeKlassen.DatasetClass&collist=afkorting%2Cnaam%2CkorteOmschrijving%2CPrivacyGevoelig%2CidentificatieString&queryFilters=currentlanguage%2Chidden&offset=1&limit=15&reqNo=1&sort=afkorting&dir=asc

So the request is without the /

If I put a custom variable in the options. This is not passed to the JSON.

Hi Jurjen,

The problem that you have with ‘/’ I suspect is, as I wrote in the previous message, because your page is actually called GeneriekeKlassen.RapJSON.WebHome. Update this in your resultPage and see if you get the results in the Network tab.

You cannot pass custom variables through options, only the already refined ones. For this scenario you should use the url option that is defined here https://extensions.xwiki.org/xwiki/bin/view/Extension/Livetable%20Macro#HParameter24options

A quick example:

  #set ($queryString = $escapetool.url({
    'xpage': 'plain',
    'outputSyntax': 'plain',
    'classname': 'GeneriekeKlassen.DatasetClass',
    'collist': 'col1,col2',
    'rowCount': 15,
    'maxPages': 10,
    'selectedColumn': 'col1',
    'extraParam': 'extraValue'
  }))
  #set ($customURL = $xwiki.getURL('GeneriekeKlassen.RapJSON.WebHome', 'get', $queryString))

  #set ($options = {
    'url' : $customURL
  })

Hi Oana,

Somehow I made an error adding the .WebHome in my test.

Everything Works now.

Thank you for your support

You’re welcome! :slight_smile:

Oana,

I have added doc_url, with the correct URL to the livetable. So the link works if I click it.

Is there a simular field you have to add to your JSON to get a correct edit link in _actions with a custom JSON?

Regards
Jurjen

To see if I fully understand. You have used the url option for your custom json page, with an extra doc_url parameter send and everything looks ok.
Now you want to add in your columns an _actions like one, that will link to the edit page of the doc_url? Or you just want to have the _actions column using your custom json page?

I have already found out I have to add

“doc_url” : $xwiki.getURL("${item}).
“doc_edit_url” : “edit_link”,
“doc_delete_url” : “delete_link”,

to the JSON

these URLS are then used in links or in the edit and delete function in the _actions of the livetable.

Now to only find a string substitute or a getURL varian for the delete and edit URL.

And this is the solution:

#set($docURL=$xwiki.getURL("${item}"))
#set($docEditURL=$docURL)
#set($docEditURL=$stringtool.replace($docEditURL,’/bin/view/’,’/bin/edit/’))
#set($docDeleteURL=$docURL)
#set($docDeleteURL=$stringtool.replace($docDeleteURL,’/bin/view/’,’/bin/delete/’))
#set($discard=$json.rows.add({
“doc_viewable” : true,
“doc_url” : “$docURL”,
“doc_edit_url” : “$docEditURL”,
“doc_delete_url” :"$docDeleteURL",

Hi Jurjen,

Cleaner than using the replace:

#set (#docEditURL = $xwiki.getURL($docReference, ‘edit’))
#set (#docDeleteURL = $xwiki.getURL($docReference, ‘delete’))

https://www.xwiki.org/xwiki/bin/view/ScriptingDocumentation/?url=http:%2F%2Fnexus.xwiki.org%2Fnexus%2Fservice%2Flocal%2Frepositories%2Fpublic%2Farchive%2Forg%2Fxwiki%2Fplatform%2Fxwiki-platform-oldcore%2F8.4.4%2Fxwiki-platform-oldcore-8.4.4-javadoc.jar%2F!%2Fcom%2Fxpn%2Fxwiki%2Fapi%2FXWiki.html%23getURL-org.xwiki.model.reference.DocumentReference-java.lang.String-java.lang.String-