Foren

Redirecting to another portlet level page

Jatinderveer Singh, geändert vor 6 Jahren.

Redirecting to another portlet level page

New Member Beiträge: 21 Beitrittsdatum: 24.02.17 Neueste Beiträge
Thanks Neil
You are a life saver. Another issue though.
One of my function is about redirecting to another portlet level page but somehow it is now working in Liferay7 portlet.
Here is what i am doing:

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();			
ActionResponse actionResponse = (ActionResponse) externalContext.getResponse();
actionResponse.setPortletMode(PortletMode.VIEW);
actionResponse.setWindowState(WindowState.NORMAL);
PortletRequest portletRequest= (PortletRequest) externalContext.getRequest();
PortletSession session = portletRequest.getPortletSession();
session.setAttribute("newPage",newPage, PortletSession.PORTLET_SCOPE);
externalContext.redirect("/views/nextPage.xhtml");

But i get the error:
 Exception on Submitjava.lang.IllegalStateException: Set render parameter has already been called

Now the thing is i am not setting any parameter for this page. What is changed, is it related to some other third party library?

Cheers!
thumbnail
Neil Griffin, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Are you trying to redirect from PageA to PageB? The code fragment that you provided would seem to indicate that you want to redirect from PageA to the same page (PageA again).

FWIW, I recommend that you read FACES-1315 in its entirety, since it is a very similar problem.

However, I think the specific problem that you are encountering might be FACES-2665.

The problem might go away if you try our SNAPSHOT jars for Liferay 7:

<repositories>
    <repository>
        <id>liferay-faces-snapshots</id>
        <name>Liferay Faces Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupid>com.liferay.faces</groupid>
        <artifactid>com.liferay.faces.bridge.ext</artifactid>
        <version>5.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupid>com.liferay.faces</groupid>
        <artifactid>com.liferay.faces.bridge.impl</artifactid>
        <version>4.1.0-SNAPSHOT</version>
        <!-- NOTE: This has a transitive dependency on com.liferay.faces.bridge.api-4.1.0-SNAPSHOT.jar -->
    </dependency>
    <dependency>
        <groupid>com.liferay.faces</groupid>
        <artifactid>com.liferay.faces.util</artifactid>
        <version>3.1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupid>com.liferay.faces</groupid>
        <artifactid>com.liferay.faces.portal</artifactid>
        <version>3.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>
Aparna Paibhale, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

New Member Beiträge: 3 Beitrittsdatum: 21.03.17 Neueste Beiträge
Hi Neil,

We tried the SNAPSHOT jars for Liferay 7, but we are still getting the same error. Any other way to go around this one ?

Regards,
Aparna
Jatinderveer Singh, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

New Member Beiträge: 21 Beitrittsdatum: 24.02.17 Neueste Beiträge
So i tried the suggested solution. Here is what my end requirement is:
Have a button in one page of portlet and click on it to redirect to another portlet level page (not a portal level page).
I have attached some source code that produces the problem. I have already added the dependencies as suggested. I donot think the issues you mentioned are related to mine.
Since we already have a customer portal , I will be happy to create a ticket there for you to better understand the code.
thumbnail
Neil Griffin, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Thanks for the reproducer. I was able to reproduce the problem. I recommend that you try this instead, which is the Liferay Faces Bridge specific (but soon to be proposed for standardization via JSR 378) way of dong a redirect with the JSF API (with the implicit help of the bridge):
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
String redirectURL = viewHandler.getRedirectURL(facesContext,
	"/WEB-INF/views/nextPage.xhtml?javax.portlet.faces.PortletMode=view&amp;javax.portlet.faces.WindowState=normal", null, false);
externalContext.redirect(redirectURL);
thumbnail
Neil Griffin, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Another thing you can try is to add a <redirect/> element in a faces-config.xml navigation-rule or a <to-view-id> with "?faces-redirect=true"
Jatinderveer Singh, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

New Member Beiträge: 21 Beitrittsdatum: 24.02.17 Neueste Beiträge
A quick question...Are you also trying various things to solve this? Is this an unknown issue? I havent made any modification to faces-config neither in the previous liferay 6.2 jsf portlet nor in the latest one. Do i need to make this modification to make it work with latest version? Could you share the modifications that you did to the code to resolve this problem?
thumbnail
Neil Griffin, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Jatinderveer,

Yes, I tried the code snippet that I pasted and it works on my system.

Calling ActionResponse.setWindowState(WindowState) prior to a calling ActionResponse.redirect(String) is not supported by Liferay Portal 7.0 and is not supported by Liferay Portal 6.2 so I'm not sure why it worked in your old environment.

The correct and supported way of doing a redirect with a different portlet mode and/or window state is according to the code I pasted.

Kind Regards,

Neil
thumbnail
Neil Griffin, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
UPDATE I had a small typo in the code that I pasted and I just corrected it. Sorry about that. You need to call ViewHandler.getRedirectURL(FacesContext,String,Map,boolean) and not ExternalContext.encodeRedirectURL(String).
thumbnail
Neil Griffin, geändert vor 6 Jahren.

RE: Redirecting to another portlet level page

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
BTW I neglected to mention that you had a typo in your viewId -- it needed to be "/WEB-INF/views/nextPage.xhtml" rather than "/views/nextPage.xhtml"