Forum Discussion

nickyates's avatar
nickyates
Mentor
12 years ago

I keep getting a message saying 'This widget could not be displayed.'

Hi Im having some issues with a attempt/recover block.  The code i have written below will loop 3 times and retrieve the the attached image url.  I have added this attempt block as some blog articles dont have an image and i will use the recover section to assign a default place holder image.  

 

<#assign threads = rest("blogs/id/sports_blog/threads/recent?page=1&page_size=3")>
<#list threads.threads.thread as t>
<#assign images = rest("${t.messages.topic.@href}/uploads/attachments")>

<#attempt>
       <#assign imageUrl = "${images.attachments.attachment.url}">
            <#recover>
             FAILED
            </#attempt>

</#list>

 

My problem is that on Lithium studio Component tab when im testing this it all works fine (the text FAILED is displayed once as i have one image which is missing) http://d.pr/i/79pQ, however when i put this component on to my page it shows me the message 'This widget could not be displayed.' rather than the FAILED text http://d.pr/i/lBJ5.  Could anyone show me why this is happening?

  • I have finally got to the bottom of this issue.  It turns out that it wasnt the attempt recover block which was causing the problem it was indeed a permissions issues as Adam mentioned in an earlier post.  If you do a rest call and you do not have the correct permissions the message 'This widget could not be displayed.' is shown, even if you are not currently using the responce from the rest call.  

     

    If you get this message and you are not sure why, check all of your API calls using in a browser and you might find a message similar to this

     

                  User -1 does not have the following permission(s) at XYZ: [ read_board ]

     

    I had to ensure that all my users had a role with the 'see boards' permission set.  This can be done in admin -> users -> roles

  • DougS's avatar
    DougS
    Khoros Oracle

    Hi Nick,

     

    I think you should be able to do what you want without needing to use an attempt/recover block -- the Message uploads/attachments call returns a list of attachments that you can loop through, but if there are no attachments it won't go into the list -- something like this:

     

    <#assign threads = rest("blogs/id/sports_blog/threads/recent?page=1&page_size=3")>
    <#list threads.threads.thread as t>
      <#assign attachments = rest("${t.messages.topic.@href}/uploads/attachments").attachments />
      <#list attachments.attachment as attachment>
        <#assign attachmentUrl = "${attachment.url}">
      </#list>
    </#list>

    If you were just using the example you gave as a way to test the attempt/recover block, I'm not sure why it's catching it on the component page but no on the actual page.  Usually, when you don't add an attempt/recover block non-admin users will see the "widget cannot be displayed" message, but admin users will see that ugly freemarker exception we all know and love.  In this case it's strange that it goes into the recover block in one case but not the other -- it may have something to do with the type of exception that is being thrown by Freemarker.

    • DougS's avatar
      DougS
      Khoros Oracle

      I created the component your add to your initial post on a test site and added it to the community page and got the FAILED message.  What page had you added the component to?  Thanks!

       

      -Doug

      • nickyates's avatar
        nickyates
        Mentor

        Hi Doug, 

         

        I will try with your code example above and hopefully that will fix my issue.

         

        I added my sample code to the community page on my site.

         

        The thing that i think is odd is that when i use my code when i am not logged in i get the error message saying 'This widget could not be displayed.' however when i am logged in as an admin i dont get the yellow freemarker exception error message and the page seems to display correctly.  I would expect the yellow freemarker exception message if i was logged in as admin.

         

        Thanks

         

        Nick