I have checked on Using custom services or liferay services in liferay themes (velocity templates)?
and Custom Methods are working fine as they are. But I have some specific requirement.
Please let me know if you know how to pass PortletSession object or RenderRequest to Custom method.
E.g.
I have tried to create the following interface:
package com.myTool;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
public interface MyTest{
public String getUserCountry(PortletSession portletSession);
public String getUserCountry(RenderRequest request);
}
In class that implements interface I have the following methods:
public String getUserCountry(PortletSession portletSession) {
try {
myUtil.setPortletSession(portletSession);
return "Success";
}
catch (Exception e) {
e.printStackTrace();
return "exception-portletSession";
}
};
public String getUserCountry(RenderRequest request) {
try {
myUtil.setPortletSession(request.getPortletSession());
return "Success request";
}
catch (Exception e) {
e.printStackTrace();
return "exception-renderRequest";
}
};
I have tried the following ways with no luck:
1)
#set($currentProfileUtil = $utilLocator.findUtil("myportlets-1.0-SNAPSHOT", "com.myTool.MyTest"))
#set($result = $currentProfileUtil.getUserCountry($request.getAttribute("javax.portlet.response")))
$result
2)
#set($currentProfileUtil = $utilLocator.findUtil("myportlets-1.0-SNAPSHOT", "com.myTool.MyTest"))
#set($result = $currentProfileUtil.getUserCountry($request.get("portlet-session")))
$result
3)
#set($currentProfileUtil = $utilLocator.findUtil("myportlets-1.0-SNAPSHOT", "com.myTool.MyTest"))
#set($result = $currentProfileUtil.getUserCountry($request.getSession()))
$result
4)
#set($currentProfileUtil = $utilLocator.findUtil("myportlets-1.0-SNAPSHOT", "com.myTool.MyTest"))
#set($result = $currentProfileUtil.getUserCountry($request.getSession()))
$result
P.S. Please do not say "why do you need this?" - just provide any ideas on how to send PortletSession or any object from which PortletSession can be retrieved. Thanks