Search code examples
javaapache-cocoon

How to get requestUri out of Cocoon into my Java function?


I inherited some old Cocoon code, if it's obvious, please tell me where in the docs I could find it.

I have a function to clean up some page parameters. I want to hand over the content to that function, but I can't manage to get there.

This is the original code, the value must pass my "cleanPath" function.

<jdbp:page-param name="pageToLoad" value="${{request.requestURI}}/../{@page}"/>

Attempt 1:

<jdbp:page-param name="pageToLoad" value="cleanPath(${{request.requestURI}}/../{@page})"/>

My attempt was to add the function in and leave everything like that, but it's not working.

My next attempt is these nice xsp:logic blocks, where I can't get the requestURI. "request.requestURI" is unknown, evaluate complains "Type mismatch: cannot convert from Object to String".

<xsp:logic>
  String input2 = evaluate("${{request.requestURI}}", String.class);
  String input = "/../<xsl:value-of select="@page"/>";
  putVariable("Hase","Test "+input);
</xsp:logic>
<jdbp:page-param name="pageToLoad" value="${{request.requestURI}}/../{@page}"/>
<jdbp:page-param name="Hase" value="${{Hase}}"/>

Solution

  • It's easy to just call request.getRequestURI();. No need for complicated wrappers.