Fórum

Create filter that sets cookie to change theme (bring in style sheet)

thumbnail
Brian Scott Schupbach, modificado 10 Anos atrás.

Create filter that sets cookie to change theme (bring in style sheet)

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
From the research I've done, this is a little more complicated than I originally thought...

I have created a filter hook and would like to set a cookie based upon a session attribute set in an email gathering portlet. Once I am able to do that, I think bringing in the additional style sheet won't be an issue. The problem I'm having is reading the session attribute set in the portlet from my filter hook and also setting a cookie in the filter hook that the rest of my portlets can read. Has anyone had any luck sharing a session attribute with a filter hook?

The filter hook only has the ServletRequest object. I try to get the HttpServletRequest object like this:

HttpServletRequest request = (HttpServletRequest) servletRequest;

The portlet has the PortletRequest object and I'm getting the HttpServletRequest like this

HttpServletRequest req = PortalUtil.getHttpServletRequest(request); //where request is the PortletRequest
HttpSession session = req.getSession();
session.setAttribute("email", email);

The session object in the portlet is not the same as in the filter from what I can tell and I'm getting the session from the HttpServletRequest in both. I'm not sure where to go from here ..

Thanks in advance,

Brian
thumbnail
Milen Dyankov, modificado 10 Anos atrás.

RE: Create filter that sets cookie to change theme (bring in style sheet)

Expert Postagens: 310 Data de Entrada: 30/10/12 Postagens Recentes
I'm not sure I understand what you are trying to do, but why don't you set the cookie you need from your portlet?
thumbnail
Brian Scott Schupbach, modificado 10 Anos atrás.

RE: Create filter that sets cookie to change theme (bring in style sheet)

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
I've tried that and the filter cannot read the cookie that the portlet sets. Maybe trying to correct that issue is the better way to solve the problem.

However, I've been reading some interesting articles from people who are suggesting setting an attribute in ThreadLocal

http://www.liferay.com/web/shuyang.zhou/blog/-/blogs/master-your-threadlocals

http://www.liferay.com/community/forums/-/message_boards/message/1294965
thumbnail
Brian Scott Schupbach, modificado 10 Anos atrás.

RE: Create filter that sets cookie to change theme (bring in style sheet)

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
After having trouble setting a cookie within the portlet, I've read about a lot of people who say the only possible way to set a cookie from a portlet is by sending back some javascript that sets the cookie on the client machine:

http://stackoverflow.com/questions/3749199/how-to-set-a-cookie-in-liferay-portlet

http://www.liferay.com/community/forums/-/message_boards/message/16889198
thumbnail
Brian Scott Schupbach, modificado 10 Anos atrás.

RE: Create filter that sets cookie to change theme (bring in style sheet)

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
Apparently you can set a cookie within a portlet by using renderResponse.setProperty. However, it appears as if there is a bug

http://issues.liferay.com/browse/LPS-25733