You have not said clearly as to, where you are using the velocity template - in themes, web-content templates etc?
I would guess it would be the theme since you gave a link at the start which describes how to use them in themes, so the short answer is you can't get PortletSession
and RenderRequest
from the velocity templates but don't worry since you can get HttpSession
and HttpServletRequest
in the template files and use it as it is used in liferay's init.vm
.
So the variable $request
is for HttpRequest
and is not for RenderRequest
and hence $request.getSession()
gives HttpSession
and not PortletSession
.
I think the reason you can't get portlet specific request and session in velocity may be because the templates are portlet agnostic and hence there is no means to know for which portlet are you asking the request
.
Anyways but all the attributes or parameters that can be there in a portlet's request are there in the HttpServletRequest
, so I guess you would need to change the method signatures to:
public interface MyTest{
public String getUserCountry(HttpSession portletSession);
public String getUserCountry(HttpServletRequest request);
}
and then use:
#set($result = $currentProfileUtil.getUserCountry($request.getSession()))
#set($result = $currentProfileUtil.getUserCountry($request))
I have tried this but you can try getting the RenderRequest
from the HttpServletRequest
:
RenderRequest renderRequest = (RenderRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
and response through:
RenderResponse renderResponse = (RenderResponse) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
Note: $request
variable is also available in web-content templates (OP's comment)
Hope this helps