Forum Discussion

cike's avatar
cike
Champion
7 years ago

Freemarker error when webuisupport to request label

Hey there,

the last days I ran into a strange issue. I set up a new Blog and some pre-defined labels to it. Well, as you can imagine, there is no content at this point.

So, when I go to the BlogPage quilt (with "label-name" in path), my Freemarker code failed and returns an error:

Java method "lithium.coreapi.webui.template.models.NamedValueByNameTemplateModel.get(String)" threw an exception when invoked on lithium.coreapi.webui.template.models.NamedValueByNameTemplateModel object "lithium.coreapi.webui.template.models.NamedValueByNameTemplateModel@50b58b98"; see cause exception in the Java stack trace.

----
FTL stack trace ("~" means nesting-related):
	- Failed at: #assign categoryFilter = webuisupport...  [in template "rexroth-hero" at line 31, column 5]
----

The LOC that raises the error, makes use of the webuisupport context object:

<#assign labelSelected = webuisupport.path.parameters.name.get("label-name").text />

I already tried to split up my variables a bit more (adding some checks and so on), but the result is still the same.

 

The issue only occurs if there are no messages with the requested label are available. Does anyone of run into the same issue and has an idea how to solve this without setting hard coded labels?

 

Thanks and best regards,

Christian

  • Are you looking to treat this situation differently or just to prevent the error from being thrown?

    I would simply wrap the webuisupport code into an <attempt> block to achieve the latter...

6 Replies

  • cike,

    Try something like this in your code.

     

    <#assign labelSelected = webuisupport.path.parameters.name.get ("label-name","") /> 
    <#if labelSelected?? && labelSelected?has_content>
    Your selected label ${labelSelected.text} 
    <!-- and then execute the query here with ${labelSelected.text} --> </#if>

     

  • cike's avatar
    cike
    Champion
    7 years ago

    I already something similar to this. But it's still the webuisupport line which fails. So, I my code never reaches the if-clause.

  • cike's avatar
    cike
    Champion
    7 years ago

    I double-check this to. The object is used in our components only. Well, as I already said, for other blog nodes, where content was created, everything works as expected.

    Maybe this a limitation by the context object webuisupport, which doesn't occur in default cases. Mostly labels will only be rendered if they were used at least one time.

    In my case the blog page with label filter is accessible all the time, even if there is no content.

  • ClaudiusH's avatar
    ClaudiusH
    Khoros Alumni (Retired)
    7 years ago

    Are you looking to treat this situation differently or just to prevent the error from being thrown?

    I would simply wrap the webuisupport code into an <attempt> block to achieve the latter...

  • cike's avatar
    cike
    Champion
    7 years ago

    ClaudiusH An <attempt> block could fix this. I just need to figure out how I can apply this to our business logic around.

    Without error handling some of my other components and content will break.