java - actionResponse.sendRedirect(url) 不起作用

标签 java liferay portlet icefaces

我有一个带有 commandLink 的 portlet。在 commandLink 的 actionListner 上,我调用了 backingBean。

支持 bean 具有以下代码。

ActionResponse actionResponse = (ActionResponse) LiferayFacesContext.getInstance().
     getExternalContext().getResponse();
actionResponse.sendRedirect("http://localhost:8080/web/guest/pageName");

我重定向到另一个 portlet 页面。两个 portlet 都包含在一次 war 中。

此重定向不起作用,它给出: classCastException。无法坚持 ActionResponse

我也尝试过,

ActionResponse actionResponse= (ActionResponse) FacesContext.getCurrentInstance().
    getExternalContext().getResponse();
actionResponse.sendRedirect("http://localhost:8080/web/guest/pageName");

它抛出ClassCastException。无法转换为 ActionResponse

异常堆栈跟踪:

java.lang.ClassCastException:com.liferay.portlet.ResourceResponseImpl 无法转换为 javax.portlet.ActionResponse 在 com.brightsky.action.IPCActionBackingBean.addIPCAction(IPCActionBackingBean.java:63) 在 sun.reflect.NativeMethodAccessorImpl.invoke0( native 方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在 java.lang.reflect.Method.invoke(Method.java:597) 在 org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328) 在 org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:341) 在 org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58) 在 org.jboss.el.parser.AstValue.invoke(AstValue.java:96) 在 org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) 在 com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102) 在 javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:144) 在 javax.faces.event.ActionEvent.processListener(ActionEvent.java:84) 在javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:773) 在javax.faces.component.UICommand.broadcast(UICommand.java:296) 在javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) 在javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) 在 com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) 在 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) 在 com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) 在 org.portletfaces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:513) 在 org.portletfaces.bridge.GenericFacesPortlet.serveResource(GenericFacesPortlet.java:131) 在 com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:119) 在 com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71) 在 com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

注意:我正在使用 Liferay 和 Icefaces。

谢谢。

最佳答案

请尝试此链接,

http://www.portletfaces.org/community/forums/-/message_boards/view_message/76606

和代码,

在你的jsp或xhtml中,

<h:commandButton id="btn1" type="submit" action="#{bean.redirectAction}" value="test redirect ajax" />

在你的bean中,

 public void redirectAction() {
   System.out.println("Action Triggrered");
    try {


        Map<String, Object> reqestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
        ThemeDisplay themeDisplay = (ThemeDisplay) reqestMap.get("THEME_DISPLAY");
             FacesContext.getCurrentInstance().getExternalContext().redirect(themeDisplay.getPortalURL() + "/web/{user-id}/home");
          } catch (IOException e) {
             // TODO Auto-generated catch block
            e.printStackTrace();
         }
      }

我也面临这个问题。使用了上述解决方案,但不起作用。 后来发现,是liferay的portletfaces-bridge jar的问题。 我实际上使用的是 portletfaces-bridge-2.0.0.jar,但这个问题在 portletfaces-bridge-2.0.1.jar 中得到了解决。

尝试使用portletfaces-bridge-2.0.1.jar。上面的代码将会工作。

如果这不适合您。然后,检查您是否使用 GenericFacesportlet。在这种情况下,您必须使用 Liferay 6.0.6。

关于java - actionResponse.sendRedirect(url) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6937057/

相关文章:

permissions - 了解liferay的权限系统

java - liferay portlet 中的 NullPointerException

java - 如何从liferay中的portlet渲染url检索查询参数值?

java - 对 ArrayList 中稍后移动的元素的引用

java - API 对于浏览器返回 200,对于 Jsoup 返回 500

java - Android Studio 请求位置权限弹窗

java - 如何查找java bean中包含的所有成员变量的字段

Liferay liferay-ui :search-toggle not showing (on search-form)

liferay - 在liferay门户中自定义用户创建过程

java - Spring MVC Controller 作为 Liferay Portlet 和 Servlet