Reputation: 382
I have developed a scheduler portlet where I need to use themeDisplay and get groupID. But, in receive method I am not able to get PortletRequest object to instantiate themeDisplay object.
public class MyScheduler implements MessageListener{
public void receive(Message message) throws MessageListenerException {
ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
long groupId = themeDisplay.getScopeGroupId();
}
}
In the above snippet how should I get "portletRequest"?
Upvotes: 2
Views: 1418
Reputation: 2862
You can't get a portlet request in a message listener that is scheduled to be triggered automatically. Scheduler event listener is completely detached from request processing. There is no portlet request to work with.
If you generated the events during a portlet request processing, you could pass the data in the payload.
Example of asynchronous message sending (eg. from portlet action phase):
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
jsonObject.put("userId", themeDisplay.getUserId());
jsonObject.put("groupId", themeDisplay.getScopedGroupId());
...
MessageBusUtil.sendMessage("tour/roadie/setup", jsonObject.toString());
I'd suggest to pass individual attributes in the payload, rather than an instance of PortletRequest
, as the request might not be valid during the message processing.
For more details, see Asynchronous Messaging With Callbacks.
Upvotes: 3