Forum Discussion

clint's avatar
clint
Advisor
10 years ago

How to build a custom thread list for display in message-list-panel

I've been trying to build a custom component that will display only unanswered threads authored by paying customers.  Our paying customers have a role assigned to them "customer", so I'm querying the REST API for a list of unanswered posts, then identifying the author of each post, querying the roles of said author, then if they have the correct role, I want to append that thread to my sequence variable, which I will feed to the "forums.widget.message-list-panel" component for display.

 

Here's my code snippet:

<#list rest("/search/messages?openresponse=true&sort_by=-topicPostDate&page_size=" + results_list_size).messages.message as message>
    
  <#assign author = message.author.login>
    
  <#assign authorID = restadmin("/users/login/${author}/id").value>
    
  <#list restadmin("/users/id/${authorID}/roles").roles.role.name as authorRole> 
    <#if authorRole?? && (authorRole == "customer")>
      
      <#assign messagelist = messagelist + message>

When I save this code, Studio throws this exception:

 

FreeMarker template error

Only elements with no child elements can be processed as text.
This element with name "message" has a child element named: thread

The failing instruction (FTL stack trace):
----------
==> #assign messagelist = messagelist + m...  [in template "preview" at line 27, column 7]
----------

But if I change my message variable to drill down to the "thread" node level, by changing this line:

 

<#assign messagelist = messagelist + message>

to this:

<#assign messagelist = messagelist + [message.thread]>

it complains that my right-hand operand is not convertible to a string:

 

For "+" right-hand operand: Expected a string or something automatically convertible to string (number, date or boolean), but this evaluated to a sequence (wrapper: f.t.SimpleSequence):
==> [message.thread]  [in template "preview" at line 27, column 44]

The failing instruction (FTL stack trace):
----------
==> #assign messagelist = messagelist + [...  [in template "preview" at line 27, column 7]
----------

What am I doing wrong?  In other languages, this is just an array that I'm trying to append to, but Freemarker doesn't seem to like that.

Ultimately, I just want to display this custom-built list of unanswered threads with this code:

 

<div class="lia-panel lia-panel-standard top-five-threads-with-no-replies-wrapper">
	<@component id="forums.widget.message-list-panel" title="${message_list_title}" messages="rest_v1:"+messagelist style="wide" numMessages="conv:"+results_list_size />
      </div>
  • Hi clint

     

    I'm no expert here, but my thinking is the square brackets which are the cause of your error, have you tried removing them? 

     

    <#assign messagelist = messagelist + message.thread>

    should hopefully work.

     

    This is just a shot in the dark though. Let me know if that helps at all

    • clint's avatar
      clint
      Advisor

      Thanks for the help RobertT, but I actually started off with that and it throws a slightly different error that I couldn't quite make sense of.

       

      This time, the code actually runs when I save it, but the Studio Preview function fails to render the preview with this error:

       

      Freemarker template 'preview' processing failed:

      RenderQueueException:Render queue error in BeginRender[forums/contributions/Optional:messagelistpanel.simplemessagelist.list.componentdisplay]: Failure reading parameter 'messageRowModelDatas' of component forums/contributions/Optional:messagelistpanel.simplemessagelist.list: lithium.boards.core.Community cannot be cast to lithium.coreapi.boards.IMessage
      • RobertT's avatar
        RobertT
        Boss

        Hi clint

         

        This error gives us a little more info, it appears that there is a render queue failure there. http://tapestry.apache.org/component-rendering.html

         

        Without knowing the code that follows in the component that you're trying to include and pass this into it becomes a bit more complex. You may need to build your own component completely to replace the standard "forums.widget.message-list-panel" component in this instance.

         

        Basically the error is telling us that rendering is out of sequence, you need to load the data before rendering. Not sure it's an easy fix though unless one of the Lithium dev's is able to provide more info?