简体   繁体   English

如何从LIferay / IceFaces / JSF Portlet支持bean中获取URL请求参数

[英]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.

相关问题 如何从Liferay portlet中的URL获取参数? - How to get parameters from URL in Liferay portlet? 如何将get-parameter传递到jsf中的backing bean? - How to pass get-parameter to backing bean in jsf? Liferay Portlet(使用JSF)-在重定向期间将参数从一个bean传递到另一个 - Liferay portlet (with JSF) - pass parameter from one bean to another during redirect 如何从Liferay中的Portlet渲染URL检索查询参数值? - How to retrieve query parameter value from portlet render url in liferay? 如何从Portlet类中获取Liferay网站名称? - How to get Liferay site name from inside Portlet class? 在 JSF bean 中获取请求 URL? - Get the request URL in a JSF bean? Liferay Portlet:Liferay友好的自定义Url参数 - Liferay portlet: liferay friendly custom Url parameter 如何反向移植6.1.1 jsf portlet以使其在6.1.0 liferay门户上运行? - How to backport a 6.1.1 jsf portlet to get it running on a 6.1.0 liferay portal? Liferay 7.3如何在portlet中获取参数值并在view.jsp中访问 - Liferay 7.3 how to get the parameter values inside a portlet and access in view.jsp JSF-应用程序设计问题。 用户登录到备份Bean B后,如何在备份Bean A中获取数据 - JSF - App design issue. How to get data in backing bean A, after user logs in to backing bean B
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM