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

8 Replies

  • DougS's avatar
    DougS
    Khoros Oracle
    12 years ago

    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
    12 years ago

    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
    12 years ago

    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

  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    If you get an error when you're not an admin, but no error where you are, then it's likely a permissions issue. I'd suggest checking to make sure that anonymous users have the proper permission to access that blog and the messages within.

     

    If you want to bypass the permissions checks, you can use the "restadmin" context object instead of "rest" when making the call. I'd definitely urge caution with the use of the restadmin context object, as you're essentially making the rest call as an admin user regardless of who's viewing the component. I don't see anything in your code that would necessarily cause concern with the restadmin call assuming you're ok with everyone having access to those attachments, but it's just something to be cautious about.

  • nickyates's avatar
    nickyates
    Mentor
    12 years ago
    Hi Adam, Doug,
    I have now removed all of my attempt/recover blocks and replaced them with if statements. I have used all of the same rest calls and no longer get the issue. Seems strange to me.

    Thanks

    NIck
  • DougS's avatar
    DougS
    Khoros Oracle
    12 years ago

    that is strange -- was there anything else in the recover block besides the FAILED message?

  • nickyates's avatar
    nickyates
    Mentor
    12 years ago
    Hi Doug,

    No there was nothing else in there. During testing I stripped the recover block down to just a failing API call or assign command (to trigger the recover section of the attempt/recover block) and just added in some text in the recover block to say that it had failed. I got the same 'this widget could not be displayed'. I used #assign to create several different ways which would cause an error each one appears to work when i am testing in studio and when i am logged in as admin but show that error message when i am not logged in. Replace the attempt/recover with a if statement with the same API calls and #assign block and everything works fine.
  • nickyates's avatar
    nickyates
    Mentor
    12 years ago

    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