How to reuse a table defined in another page?

Dear,

Firstly thanks for your awesome works. I have a general page with a table like this:

| = Document Name | = Team | = Category | = Date
|                 |        |            |

I would like to reuse data stored in this table, for example

  • for each team pages filter each row where team = foo
  • for each category pages filter each row where category = foo

Thanks for your help

Hi. Seems you’re interested in structured content. See:

Thanks for your quick reply,

I have not get a success with Livetemplate and custom json.
currently, I created a page named ArticlesJSON at root of wiki (it is not a terminal page as I do not have the checkbox as see in your video tutorial)

On another page

I put this code

{{velocity}}
#set($columns = ["doc_viewable", "user" , "message" ])
#set($columnsProperties = {
    "doc_viewable": {"type" : "boolean" },
    "user" : { "type" : "text" },
    "message" : { "type" : "text"}
})
#set($options = { 
  "url": "http://wiki.cnrgh.fr/bin/get/ArticlesJSON?outputSyntax=plain"
})
#livetable("articles" $columns $columnsProperties $options)

{{/velocity}}

An empty live table is rendered!
If I inspect the network I can see this request:

http://wiki.somewhere.com/bin/get/ArticlesJSON?outputSyntax=plain&offset=1&limit=15&reqNo=2&doc_viewable=1&sort=doc_viewable&dir=asc

This query goes to the right page and display this on my browser:

{{velocity wiki="false"}}
#if("$!{request.xpage}" == 'plain')
  $response.setContentType('application/json')
#end
##==============================
## Offset = item # at which to start displaying data
##==============================
#set($offset = $numbertool.toNumber($request.get('offset')))
## offset starts from 0 in velocity and 1 in javascript
#set($offset = $offset - 1)
#if($offset < 0)
  #set($offset = 0)
#end
##==================
## Limit = # of items to display
##==================
#set($limit = $numbertool.toNumber($request.get('limit')))
##==================
## Tag = one parameter per tag
##==================
#if($request.tag)
  #foreach($tag in $request.getParameterValues('tag'))
    ## TODO: Add code to filter items based on the selected tags
  #end
#end
##==========
## Sort direction
##==========
#set($order = "$!request.sort")
#if($order != '')
  #set($orderDirection = "$!{request.get('dir').toLowerCase()}")
  #if("$!orderDirection" != '' && "$!orderDirection" != 'asc')
    #set($orderDirection = 'desc')
  #end
#end
## ===========
## Filter Data here...
## ===========
## TODO: Add code to filter data
## Each column can be filtered and the filter for a column can be retrieved with:
## #set($filterValue = "$!{request.get(<columnname>)}")

## ===
## JSON
## ===
{
"totalrows": 1,
"matchingtags": {},
"tags" : [],
"returnedrows":  1,
"offset": 1,
"reqNo": $util.parseInt($request.reqNo),
"rows": [{
  "doc_viewable" : true,
  "user" : "vincent",
  "message" : "my message"
}]
}
{{/velocity}}

So I do not know why the live table is empty, I will continue to do some test

Thanks

So currently I created a class named Article
I can see on the final pages that the request generated is:

http://wiki.somewhere.fr/bin/get/XWiki/LiveTableResults?outputSyntax=plain&transprefix=article.livetable.&classname=Article.Code.ArticleClass&collist=doc.title%2CshortText2%2Cdate1%2Cpage1%2CshortText3&queryFilters=currentlanguage%2Chidden&offset=1&limit=15&reqNo=3&doc.title=ev&sort=doc.title&dir=asc

So on another page I created a livetable to query it

{{velocity}}
#set($columns = ["Page Title", "url" , "date" ])
#set($columnsProperties = {
    "Page Title": { "type" : "text", "sortable":true },
    "url" : { "type" : "text", "link" : "view", "html" : "true", "sortable":true },
    "date" : { "type" : "date", "sortable":true}
})
#set($options = { "transprefix": "article.livetable.",
                  "Classname": "Article.Code.ArticleClass",
                  "rowCount": 10 })
#livetable("Article" $columns $columnsProperties $options)

{{/velocity}}

But the query fails with this message:

Failed to execute the [velocity] macro. Cause: [Invalid path: 'obj.id' [select elements(prop.list) from com.xpn.xwiki.doc.XWikiDocument as doc, com.xpn.xwiki.objects.BaseObject as tagobject, com.xpn.xwiki.objects.DBStringListProperty as prop, com.xpn.xwiki.objects.StringProperty as prop_PageTitle  where (doc.hidden <> true or doc.hidden is null) and (tagobject.name=doc.fullName and tagobject.className='XWiki.TagClass' and tagobject.id=prop.id.id and prop.id.name='tags' and doc.translation=0 and 1=1  and obj.id = prop_PageTitle.id.id and prop_PageTitle.id.name = ? and (upper(prop_PageTitle.value) like upper(?)))]]. Click on this message for details.org.xwiki.rendering.macro.MacroExecutionException: Failed to evaluate Velocity Macro for content [## the $extra variable is passed to the call to #gridresultwithfilter below and is used to perform some default
## filtering on the LiveTable data even when the user has not performed any column filtering yet.
## When users start using column filtering, the generated DB query will combine both the default filtering and what the
## user has entered in the column filters.
#set ($extra = '')
#set ($params = [])
#if ("$!request.space" != '')
  #set ($extra = "${extra} AND doc.space = ?")
  #set ($discard = $params.add($request.space))
#end
#addLivetableLocationFilter($extra, $params, $!request.location)
#if ("$!request.parent" != '')
  #set ($extra = "${extra} and doc.parent = ?")
  #set ($discard = $params.add($request.parent))
#end
#if ("$!request.orphaned" == '1')
  #set ($homepage = $services.wiki.getById($services.wiki.currentWikiId).mainPageReference)
  #set ($homepageFullName = $services.model.serialize($homepage, 'local'))
  ## On Oracle the empty parent is actually null.
  #set ($extra = "${extra} and (doc.parent = '' or doc.parent is null) and doc.fullName <> ?")
  #set ($discard = $params.add($homepageFullName))
#end
#gridresultwithfilter("$!request.classname" $request.collist.split(',') '' "${extra}" $params)]
	at org.xwiki.rendering.internal.macro.velocity.VelocityMacro.evaluateString(VelocityMacro.java:139)
	at org.xwiki.rendering.internal.macro.velocity.VelocityMacro.evaluateString(VelocityMacro.java:52)
	at org.xwiki.rendering.macro.script.AbstractScriptMacro.evaluateBlock(AbstractScriptMacro.java:286)
	at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:182)
	at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:58)
	at org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:297)
	at org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)
	at org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:101)

Could you double check:

  • That the ArticleClass page reference is Article.Code.ArticleClass and not Article.Code.ArticleClass.WebHome.
  • That the Article Class has 3 properties having an id of “Page Title”, “url” and “date”? “Page Title” looks more like a display name than an id. Could you show us a screenshot of your article class in the class editor with the properties unfolded?
  • Could you paste the result of opening the http://wiki.somewhere.fr/bin/get/XWiki/LiveTableResults?outputSyntax=plain&transprefix=article.livetable.&classname=Article.Code.ArticleClass&collist=doc.title%2CshortText2%2Cdate1%2Cpage1%2CshortText3&queryFilters=currentlanguage%2Chidden&offset=1&limit=15&reqNo=3&doc.title=ev&sort=doc.title&dir=asc url in your browser?

Thanks

I am currently checking so it is in progress, below the requested screenshot

thanks a lot

xwiki_livetable

{
  "reqNo": 3,
  "matchingtags": {},
  "tags": [],
  "totalrows": 1,
  "returnedrows": 1,
  "offset": 1,
  "rows": [
    {
      "doc_viewable": true,
      "doc_fullName": "Article.Evaluating Workflow Management Systems: A Bioinformatics Use Case",
      "doc_space": "Article",
      "doc_location": "                                                                                                                                                                    <ol  class=\"breadcrumb breadcrumb-expandable\" data-entity='Article.Evaluating Workflow Management Systems: A Bioinformatics Use Case' data-limit='5' data-plain='false' data-local='true' data-displaytitle='false'><li\n                                    class=\"space\"><a href=\"/bin/view/Article/\"\n        >Article</a></li><li                                                          class=\"document active\"><a href=\"/bin/view/Article/Evaluating%20Workflow%20Management%20Systems%3A%20A%20Bioinformatics%20Use%20Case\"\n        >Evaluating Workflow Management Systems: A Bioinformatics Use Case</a>      </li></ol>\n  ",
      "doc_url": "/bin/view/Article/Evaluating%20Workflow%20Management%20Systems%3A%20A%20Bioinformatics%20Use%20Case",
      "doc_space_url": "/bin/view/Article/",
      "doc_wiki": "xwiki",
      "doc_wiki_url": "/bin/view/Main/",
      "doc_hasadmin": true,
      "doc_hasedit": true,
      "doc_hasdelete": true,
      "doc_edit_url": "/bin/edit/Article/Evaluating%20Workflow%20Management%20Systems%3A%20A%20Bioinformatics%20Use%20Case",
      "doc_copy_url": "/bin/view/Article/Evaluating%20Workflow%20Management%20Systems%3A%20A%20Bioinformatics%20Use%20Case?xpage=copy",
      "doc_delete_url": "/bin/delete/Article/Evaluating%20Workflow%20Management%20Systems%3A%20A%20Bioinformatics%20Use%20Case",
      "doc_rename_url": "/bin/view/Article/Evaluating%20Workflow%20Management%20Systems%3A%20A%20Bioinformatics%20Use%20Case?xpage=rename&step=1",
      "doc_name": "Evaluating Workflow Management Systems: A Bioinformatics Use Case",
      "doc_hascopy": true,
      "doc_hasrename": true,
      "doc_hasrights": true,
      "doc_rights_url": "/bin/edit/Article/Evaluating%20Workflow%20Management%20Systems%3A%20A%20Bioinformatics%20Use%20Case?editor=rights",
      "doc_author_url": "/bin/view/XWiki/jmercier",
      "doc_date": "2019/05/17 13:55",
      "doc_title": "Evaluating Workflow Management Systems: A Bioinformatics Use Case",
      "doc_author": "Jonathan MERCIER",
      "doc_creationDate": "2019/05/17 13:55",
      "doc_creator": "Jonathan MERCIER",
      "shortText2": "https://ieeexplore.ieee.org/document/8621141",
      "shortText2_value": "https://ieeexplore.ieee.org/document/8621141",
      "shortText2_url": "",
      "date1": "<p>24/01/2019</p>",
      "date1_value": "Thu Jan 24 00:00:00 UTC 2019",
      "date1_url": "",
      "page1": "          <a href=\"/bin/view/Equipes/LBI/\">LBI</a>\n\n",
      "page1_value": "Equipes.LBI.WebHome",
      "page1_url": "/bin/view/Equipes/LBI/",
      "shortText3": "10.1109/BIBM.2018.8621141",
      "shortText3_value": "10.1109/BIBM.2018.8621141",
      "shortText3_url": ""
    }
  ]
}

Ok cool so you can see in the returned data that the fields are named “shortText2”, “date1”, “page1” and “shortText3”. This is what you need to use in the LT columns.

ofc you can also use the “doc_*” properties.

Thanks a lot I will apply your fixes and after mark as solved this thread.

I fought that I should used the property named defined for the class but in fact, I was just confused

Now that said, the reported error is really not nice and could be improved :slight_smile: You could raise a jira issue for that if you want, at https://jira.xwiki.org

for the record doc_title do not work but that is good with doc.title

Thanks

As I mentioned you need to read https://extensions.xwiki.org/xwiki/bin/view/Extension/Livetable%20Macro#HAllacceptedvalues-1 which contains all valid values. When I said “ofc you can also use the “doc_*” properties.”, I was doing this from memory only… :wink: