[英]How to get url request parameter from inside LIferay/IceFaces/JSF portlet backing bean
Is posible for a portlet to read a request parameter of its surrounding page? Portlet是否可以读取其周围页面的请求参数?
Eg the URL of the page the portlet resides in is http://example.com/mygroup/mypage?foo=bar Is it possible to read the "foo" parameter from a portlet that is on that page? 例如,Portlet所在的页面的URL是http://example.com/mygroup/mypage?foo=bar是否可以从该页面上的Portlet读取“ foo”参数?
Portlet Container is Liferay 6.0.5. Portlet容器是Liferay 6.0.5。
PS PS
I have already tried: 我已经尝试过:
com.liferay.portal.util.PortalUtil.getOriginalServletRequest(com.liferay.portal.util.PortalUtil.getHttpServletRequest((javax.portlet.PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest())).getParameter("foo")
but I always get null for productId 但是我的productId总是为null
Thanks! 谢谢!
The following code will do the trick: 以下代码可以解决问题:
javax.portlet.PortletRequest pr = (javax.portlet.PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("javax.portlet.request");
java.lang.reflect.Method method = pr.getClass().getMethod("getOriginalHttpServletRequest");
HttpServletRequest httpServletRequest = (HttpServletRequest)method.invoke(pr, new Object[] {});
return httpServletRequest.getParameter(YOUR_PARAM_KEY);
你有没有尝试过
ExternalContext.getRequestParameterMap()
In a partial submit, the icefaces ajax bridge (which replaces a usual jsf portlet bridge) is avoiding the normal portal action/render request, contacting directly the blocking servlet (in order to avoid invalidating other request-scoped portlets and in general, to be faster). 在部分提交中,icefaces ajax桥(代替了普通的jsf portlet桥)避免了正常的门户网站操作/呈现请求,直接联系了阻塞的servlet(以避免使其他请求范围内的portlet无效,并且通常是快点)。 Because of this, all those params/attributes which are set in a normal portal request are not set in ajax.
因此,在常规门户网站请求中设置的所有那些参数/属性都不会在ajax中设置。 They are set only in the initial GET type request for that page.
仅在该页面的初始GET类型请求中设置它们。 So, actually what you should do is saving those params in the @PostConstruct or some other method of your controlling bean, and then reuse them later.
因此,实际上您应该做的是将这些参数保存在@PostConstruct或控制bean的其他方法中,然后在以后重用它们。 (They wouldn't change in a partial submit anyway, right?).
(无论如何,他们不会在部分提交中进行更改,对吧?)。 Keep in mind though, that this will not work if you use IceFaces in conjuction with Spring (and their EL Resolver, since that eliminates your extended request scope).
但是请记住,如果将IceFaces与Spring(及其EL Resolver)结合使用,则无法使用此功能,因为这消除了扩展的请求范围。
如果您在JSF环境中,请尝试以下操作:
String param = LiferayFacesContext.getInstance().getRequestQueryStringParameter("foo");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.