在ActionListener中访问HttpServletRequest

时间:2012-12-30 21:06:23

标签: jsf weblogic portlet jsf-1.2

我有一个ActionListener的JSF按钮,如下所示,

<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

1 个答案:

答案 0 :(得分:1)

我通过访问“ActionRequest的javax.servlet.request”获得了HttpServletRequest。