开发者

actionResponse.sendRedirect(url) not working

I have one portlet which has a commandLink. On the actionListner of commandLink I called the backingBean.

The backing bean has the following code.

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

I have a redirect to the another portlet page. Both portlets are contained in a single war.

This redirection is not working, it gives: classCastException. can't clast to ActionResponse

I have also tried for,

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

It Throws ClassCastException. Can not cast to ActionResponse

Exception StackTrace :

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

NOTE : I m using Liferay & Icefaces.

Thank you.


Please try this link,

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

and code,

in your jsp or xhtml,

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

in your 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();
         }
      }

I was facing this problem as well. Used the above solution but was not working. Later identified that, it is the problem with the liferay's portletfaces-bridge jar. I was actually using portletfaces-bridge-2.0.0.jar, but this issue got resolved in portletfaces-bridge-2.0.1.jar.

Try to use portletfaces-bridge-2.0.1.jar. and the above code will work.

If this is not working for you. Then, check if you are using GenericFacesportlet. In that case, you have to use Liferay 6.0.6.


I used to have similar problem using actionResponse.sendRedirect() in my last project work with Spring and Liferay, though Spring gave me a more clear exception

Set render parameter has already been called.

This method actionReponse.sendRedirect() is quite restricted during the portlet life cycle. according to the Portlet API, it can not be invoked after any of the following methods of the ActionResponse interface has been called:

  • setPortletMode
  • setWindowState
  • setRenderParameter
  • setRenderParameters
  • removePublicRenderParamter

It is very likely that your portlet framework set the PortletMode and RenderParameter at some point before you code. I know Spring does this when declare portlet related beans in the context (though the original idea is to make developer's life more easier by DI). If you cannot fix this within your existing portlet framework infrastructure. A possible solution is write your own javax.portlet.filter, examine the action name, and call sendRedirect() properly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜