Forum Discussion

Henrik's avatar
Henrik
Advisor
12 years ago

http.request FreeMarker context object

Hi everyone,

 

I’ve been testing the http.request FreeMarker context object, given in the lithosphere:

http.request Knowledge Base Article

 

Unfortunately, there is one object I cannot manage to use: http.request.attributes.name.get("attribute name", default value)

 

I cannot get a "foo" parameter with ${http.request.parameters.name.get("foo", 2)}. It throws the following error. Could you help me on that issue? Thank you!

 

FreeMarker template error

Method public final java.lang.Object lithium.coreapi.webui.template.models.NamedValueByNameTemplateModel.get(java.lang.String,java.lang.Object) threw an exception when invoked on lithium.coreapi.webui.template.models.NamedValueByNameTemplateModel object "lithium.coreapi.webui.template.models.NamedValueByNameTemplateModel@37d8c40e" with arguments of types [java.lang.String,java.math.BigDecimal,]. See cause exception. The failing instruction (FTL stack trace):----------==> ${http.request.parameters.name.get("f...  [in template "CustomContent" at line 3, column 1]

 

  • Hi Henrik,

     

    I think the problem in your example is that you are mixing types (there is a string in the first parameter, and and integer in the second one). Both parameters should be a string. If you need to convert the string to a number, you can do it using freemarker

     

    ${http.request.parameters.name.get("foo", "2")?number}

     Hope this helps,

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi Henrik,

     

    I think the problem in your example is that you are mixing types (there is a string in the first parameter, and and integer in the second one). Both parameters should be a string. If you need to convert the string to a number, you can do it using freemarker

     

    ${http.request.parameters.name.get("foo", "2")?number}

     Hope this helps,

    • Henrik's avatar
      Henrik
      Advisor

      Hi Paolo,

       

      Thank you for the help. It worked!

      Henrik