Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mirko Tikalsky
Problem with redirection from Icefaces portlet
January 13, 2011 7:44 AM
Answer

Mirko Tikalsky

Rank: New Member

Posts: 1

Join Date: January 13, 2011

Recent Posts

Hello,
Currently I'm trying to upgrade my various icefaces 1.8.2 portlets, that have been running on Liferay 5.2.3 to the new Icefaces version 2.0 and Liferay 6.0.
During that I encounter a problem with user driven redirection.

What I want to do is e.g. having 2 portal pages defined in liferay (lets say Page1 and Page2). Both pages hold a different Icefaces portlet (e.g. Portlet1 and Portlet2). Now I want in my one portlet (1) to present a link (commandLink) that calls an action method on my BackingBean. Inside that action method I want the user to get redirected to portalPage 2.

Strangley I get the following StackTrace, when it comes to execution:


  1
  2java.io.UnsupportedEncodingException: Unable to redirect during RESOURCE_PHASE (can only be done during ACTION_PHASE)
  3        at org.portletfaces.bridge.container.liferay.PortletContainerLiferayImpl.redirect(PortletContainerLiferayImpl.java:248)
  4        at org.portletfaces.bridge.context.ExternalContextImpl.redirect(ExternalContextImpl.java:382)
  5        at com.nx.TestBean.doRedirectionTest(TestBean.java:17)
  6        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  7        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  8        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  9        at java.lang.reflect.Method.invoke(Method.java:597)
 10        at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
 11        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
 12        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102)
 13        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84)
 14        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
 15        at javax.faces.component.UICommand.broadcast(UICommand.java:311)
 16        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:783)
 17        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1248)
 18        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
 19        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
 20        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
 21        at org.portletfaces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:289)
 22        at org.portletfaces.bridge.GenericFacesPortlet.serveResource(GenericFacesPortlet.java:173)
 23        at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:119)
 24        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
 25        at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
 26        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 27        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 28        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 29        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 30        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
 31        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
 32        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
 33        at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:635)
 34        at com.liferay.portlet.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:747)
 35        at com.liferay.portlet.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:504)
 36        at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:847)
 37        at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:602)
 38        at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:229)
 39        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 40        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 41        at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:152)
 42        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 43        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 44        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 45        at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:508)
 46        at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:485)
 47        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 48        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 49        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 50        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 51        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 52        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 53        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 54        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 55        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 56        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 57        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 58        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 59        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 60        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 61        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 62        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 63        at com.liferay.portal.servlet.filters.themepreview.ThemePreviewFilter.processFilter(ThemePreviewFilter.java:88)
 64        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 65        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 66        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 67        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 68        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:137)
 69        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 70        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 71        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 72        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 73        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
 74        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 75        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 76        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 77        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 78        at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
 79        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
 80        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 81        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 82        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 83        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
 84        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
 85        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
 86        at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:133)
 87        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 88        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 89        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 90        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 91        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 92        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 93        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 94        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 95        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
 96        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 97        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 98        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
 99        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
100        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
101        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
102        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
103        at com.liferay.portal.servlet.filters.themepreview.ThemePreviewFilter.processFilter(ThemePreviewFilter.java:88)
104        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
105        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
106        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
107        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
108        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:137)
109        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
110        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
111        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
112        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
113        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
114        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
115        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
116        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
117        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
118        at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:221)
119        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
120        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
121        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
122        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
123        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
124        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
125        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
126        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
127        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
128        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
129        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
130        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
131        at com.liferay.portal.servlet.filters.etag.ETagFilter.processFilter(ETagFilter.java:45)
132        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
133        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
134        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
135        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
136        at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
137        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
138        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
139        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
140        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
141        at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:81)
142        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
143        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
144        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
145        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
146        at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:179)
147        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
148        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
149        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
150        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
151        at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:239)
152        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
153        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
154        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
155        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
156        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
157        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
158        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
159        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
160        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
161        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
162        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
163        at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
164        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
165        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
166        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
167        at com.liferay.portal.servlet.filters.threadlocal.ThreadLocalFilter.processFilter(ThreadLocalFilter.java:35)
168        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
169        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
170        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
171        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
172        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
173        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
174        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
175        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
176        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
177        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
178        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
179        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
180        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
181        at java.lang.Thread.run(Thread.java:619)


My BackingBean method looks like:

 1
 2package com.nx;
 3
 4import java.io.IOException;
 5import java.io.Serializable;
 6
 7import javax.faces.context.FacesContext;
 8
 9public class TestBean implements Serializable {
10
11    private static final long serialVersionUID = 1L;
12
13    public TestBean() {    }
14   
15    public String doRedirectionTest() {
16        String redirectUrl = "http://localhost:8080/web/guest/page2";
17        try {
18            FacesContext.getCurrentInstance().getExternalContext().redirect(FacesContext.getCurrentInstance().getExternalContext().encodeRedirectURL(redirectUrl, null));
19        } catch (IOException e) { e.printStackTrace(); }
20        return "";
21    }
22}


And my xhtml page looks like:

 1
 2<html xmlns="http://www.w3.org/1999/xhtml"
 3      xmlns:h="http://java.sun.com/jsf/html"
 4      xmlns:f="http://java.sun.com/jsf/core"
 5      xmlns:ice="http://www.icesoft.com/icefaces/component"
 6      xmlns:ui="http://java.sun.com/jsf/facelets"
 7      locale="en">
 8
 9    <h:head/>
10    <h:body>
11
12       <ice:form>
13               <ice:outputText value="hello world"/>
14               <ice:commandLink action="#{testBean.doRedirectionTest}" value="Test redirection"/>
15       </ice:form>
16
17    </h:body>
18</html>


I do not understand why this happens? Previously (Icefaces 1.8.2 and Liferay 5.2.3) this kind of redirection worked for me.
I would really appreciate any help!

Thanks in advance
Kind regards
Mirko

Edit: Attached the sample portlet project
Attachments: testPortlet.zip (42.0k)
vasv kumar
RE: Problem with redirection from Icefaces portlet
August 5, 2011 4:13 AM
Answer

vasv kumar

Rank: Junior Member

Posts: 46

Join Date: February 7, 2011

Recent Posts

Try this and it is working fro us
 1public svoid redirect(String url) throws IOException {
 2        PortletResponse portletResponse = getPortletResponse();
 3        if (portletResponse instanceof ActionResponse) {
 4            LiferayPortletResponse liferayActionResponse = new LiferayPortletResponse(portletResponse);
 5            liferayActionResponse.sendRedirect(url);
 6        } else if (portletResponse instanceof ResourceResponse) {
 7            final FacesContext ctx = FacesContext.getCurrentInstance();
 8            if (ctx.getPartialViewContext().isPartialRequest()) {
 9                ResourceResponse portletResourceResponse = (ResourceResponse) portletResponse;
10                PartialResponseWriter pwriter;
11                ResponseWriter writer = ctx.getResponseWriter();
12                if (writer instanceof PartialResponseWriter) {
13                    pwriter = (PartialResponseWriter) writer;
14                } else {
15                    pwriter = ctx.getPartialViewContext().getPartialResponseWriter();
16                }
17                portletResourceResponse.setContentType("text/xml");
18                portletResourceResponse.setCharacterEncoding("UTF-8");
19                // addResponseHeader("Cache-Control", "no-cache");
20                pwriter.startDocument();
21                pwriter.redirect(url);
22                pwriter.endDocument();
23                ctx.responseComplete();
24            } else {
25                throw new UnsupportedEncodingException(
26                        "Can only redirect during RESOURCE_PHASE if a Partial-(JSF AJAX)-Request  has been triggered");
27            }
28        } else {
29            throw new UnsupportedEncodingException("Can not redirect during the current phase: "
30                    + portletResponse.getClass().getSimpleName());
31        }
32    }