【发布时间】:2012-12-15 04:52:49
【问题描述】:
我有一个用于 JSF 按钮的ActionListener,如下所示,
<h:commandButton id="id1" action="#{Mybean.Submit}" value="Click">
<f:actionListener binding="#{Mybean.actionListenerImpl}" type="bean.ActionListenerImpl" />
</h:commandButton>
ActionListener的实现如下,
public void processAction(ActionEvent event) throws AbortProcessingException {
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest req = (HttpServletRequest)fc.getExternalContext().getRequest();
PortletBackingContext pbc = PortletBackingContext.getPortletBackingContext(req);
pbc.fireCustomEvent("test", "test");
}
但这会引发以下异常:
java.lang.ClassCastException: com.bea.portlet.container.ActionRequestImpl cannot be cast to javax.servlet.http.HttpServletRequest
at bean.ActionListenerImpl.processAction(ActionListenerImpl.java:18)
我需要访问HttpServletRequest 以获取PortletBackingContext 对象,通过该对象我可以触发自定义事件。
我在 weblogic 10.3.0 中使用 JSF 1.2
【问题讨论】:
-
您在 portlet 容器而不是 servlet 容器上运行 JSF。为什么您希望它返回一个 servlet 请求而不是一个 portlet 请求?您最好将您的问题重新定义为“如何在 JSF 托管 bean 中获取 PortletBackingContext 的当前实例?”而不是问如何实现一个不可能的解决方案(好吧,假设您不能将 portlet 容器简单地更改为像 Tomcat/JBoss/Glassfish 这样的 servlet 容器)。
-
但是要获得 PortletBackingContext,我们需要将 HttpServletRequest 作为参数传递。还有其他方法可以从 JSF bean 获取 PortletBackingContext 吗?
-
我通过访问“javax.servlet.request of ActionRequest”得到了HttpServletRequest。
标签: jsf weblogic portlet jsf-1.2