留言板

Set PortletSession Attribute in LoginPostAction

Morad Ahmad,修改在6 年前。

Set PortletSession Attribute in LoginPostAction

Junior Member 帖子: 71 加入日期: 10-6-16 最近的帖子
Hi,

I want to set an Attribute value in PortletSession (ApplicationScope) after the user login. The value is normally stored in DB (Expando-Table or other)

public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
String path = getUserLandingPage(request);
if (StringUtils.isNotBlank(path)) {
setRegionValue(request);
try {
response.sendRedirect(path);
} catch (IOException e) {
_log.warn(e.getMessage());
}
}
}


private void setPortletSessioRegionValue(HttpServletRequest request, long groupId, int regionValue) {
_log.info("setPortletSessioRegionValue, regionValue= " + regionValue);
// ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
HttpSession httpSession = request.getSession(false);
tmp_printRequest(request);
PortletRequest portletRequest = (PortletRequest) httpSession.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
System.out.println("portletRequest: " + portletRequest);
if (portletRequest != null) {
PortletSession portletSession = portletRequest.getPortletSession();
portletSession.setAttribute("region", String.valueOf(regionValue), PortletSession.APPLICATION_SCOPE);
} else {
Map<Long, Integer> groupRegions = new HashMap<Long, Integer>();
groupRegions.put(groupId, regionValue);
httpSession.setAttribute("regionsMap", groupRegions);
}
}

How to get/set attribute value in PortletSession "beginning" from a HttpServletRequest request??

Thanks,
Morad.