简体   繁体   中英

JSF 2.1 Redirect to a portlet

I upgraded my liferay to 6.0 and JSF from 1.2 to 2.1. My existing code

 ((ActionResponse)context.getExternalContext().getResponse()).sendRedirect( redirect );
context.responseComplete();

Here redirect is defined as follows:

String redirect = "/namingportal/group/customercenter/accountSearch";

The above URL is the portlet page to which the request must be redirected.

Started breaking with the error: java.lang.IllegalStateException: Set render parameter has already been called at com.liferay.portlet.ActionResponseImpl.sendRedirect(ActionResponseImpl.java:48)

After doing some google, I figured that the above code should be replaced with the following:

Solution 1:

context.getExternalContext().redirect(redirect);

When I tried with Solution 1, its giving me the error FacesFileNotFound /namingportal/group/customercenter/accountSearch.xhtml, its actually looking for the xhtml and not for the portlet.

I also have this in my web.xml:

<context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

Please let me know if there is any other alternative way to redirect to portlet from JSF managed bean method using Liferay 6.0 and JSF 2.1.

Thanks

The bridge adheres to the JSR 329 Spec requirements for ExternalContext.redirect(String), which provides a standard way to achieve what you want to do.

In most cases, ExternalContext.redirect(String) is assumed by the bridge to be part of a JSF navigation-rule firing. However, there are two ways to make it work in your case:

1) Add the Bridge.DIRECT_LINK parameter to the URL with a value of "true":

String redirect = "/namingportal/group/customercenter/accountSearch?javax.portlet.faces.DirectLink=true";
externalContext.redirect(redirect);

2) Make the URL to be absolute, like this:

PortletRequest portletRequest = externalContext.getRequest();
ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute("THEME_DISPLAY");
String portalURL = themeDisplay.getPortalURL();
String redirect = portalURL + "/namingportal/group/customercenter/accountSearch";
externalContext.redirect(redirect);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM