Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Brian Scott Schupbach
Create filter that sets cookie to change theme (bring in style sheet)
12 de Junho de 2013 11:23
Resposta

Brian Scott Schupbach

Ranking: Expert

Mensagens: 331

Data de entrada: 23 de Outubro de 2008

Mensagens 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
Milen Dyankov
RE: Create filter that sets cookie to change theme (bring in style sheet)
12 de Junho de 2013 12:00
Resposta

Milen Dyankov

LIFERAY STAFF

Ranking: Regular Member

Mensagens: 219

Data de entrada: 30 de Outubro de 2012

Mensagens 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?
Brian Scott Schupbach
RE: Create filter that sets cookie to change theme (bring in style sheet)
12 de Junho de 2013 12:06
Resposta

Brian Scott Schupbach

Ranking: Expert

Mensagens: 331

Data de entrada: 23 de Outubro de 2008

Mensagens 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
Brian Scott Schupbach
RE: Create filter that sets cookie to change theme (bring in style sheet)
12 de Junho de 2013 12:23
Resposta

Brian Scott Schupbach

Ranking: Expert

Mensagens: 331

Data de entrada: 23 de Outubro de 2008

Mensagens 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
Brian Scott Schupbach
RE: Create filter that sets cookie to change theme (bring in style sheet)
12 de Junho de 2013 13:58
Resposta

Brian Scott Schupbach

Ranking: Expert

Mensagens: 331

Data de entrada: 23 de Outubro de 2008

Mensagens 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