Foren

deep linking inside jsf portlet from outside

Eric Soucy, geändert vor 9 Jahren.

deep linking inside jsf portlet from outside

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Hi,
from my jsf portlet, I need to redirect to a third party site and give this site a " return URL" that leads back to a specific view inside my portlet within the same session.
This view must be different than my starting point.
From this third party site, the user will perform an action and be redirected to the " return URL".

With liferay and JSF, how can I build this return URL ?


Thanks
Eric
thumbnail
Neil Griffin, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

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

I would recommend that the return URL should be a portlet RenderURL and you can navigate to a different viewId with Bridge.FACES_VIEW_ID_PARAMETER. For example:

<portlet:renderURL var="#{returnURL}">
<portlet:param name="_jsfBridgeViewId" value="/views/otherView.xhtml" />
</portlet:renderURL>

<a href="#{returnURL}">click here to navigate to the returnURL via HTTP GET</a>

Kind Regards,

Neil
Eric Soucy, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Thanks,
I need to do this programmaticaly since I must provide this "return url" in a http rest call.
How can I create a renderURL with the API ?

Thanks again

Eric


Neil Griffin:
Hi Eric,

I would recommend that the return URL should be a portlet RenderURL and you can navigate to a different viewId with Bridge.FACES_VIEW_ID_PARAMETER. For example:

<portlet:renderURL var="#{returnURL}">
<portlet:param name="_jsfBridgeViewId" value="/views/otherView.xhtml" />
</portlet:renderURL>

<a href="#{returnURL}">click here to navigate to the returnURL via HTTP GET</a>

Kind Regards,

Neil
Eric Soucy, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
i dont want to show the return url in my view, just pass it along to 3rd party external site.
here is what i've done

        PortletDisplay portletDisplay= themeDisplay.getPortletDisplay();
        String portletId = portletDisplay.getId();

        com.liferay.portal.kernel.portlet.LiferayPortletURL myActionURL  = PortletURLFactoryUtil.create(req, portletId, themeDisplay.getPlid(), "1");
        myActionURL.setParameter("_jsfBridgeViewId", "/views/view3.xhtml");

but this gives me :
https://localhost:8443/web/test/test-portlet?p_p_id=&amp;___jsfBridgeViewId=%2Fviews%2Fview3.xhtml


what I need is this :

https://localhost:8443/web/test/test-portlet?p_p_id=portlettestnetbanx_WAR_portlettestnetbanx&amp;p_p_lifecycle=0&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_count=1&amp;_portlettestnetbanx_WAR_portlettestnetbanx__jsfBridgeViewId=%2Fviews%2Fview3.xhtml
         * this also works
         * https://localhost:8443/web/test/test-portlet?p_p_id=portlettestnetbanx_WAR_portlettestnetbanx&amp;p_p_lifecycle=0&amp;_portlettestnetbanx_WAR_portlettestnetbanx__jsfBridgeViewId=%2Fviews%2Fview3.xhtml
         * and this also works as well: https://localhost:8443/web/test/test-portlet?p_p_id=portlettestnetbanx_WAR_portlettestnetbanx&amp;_portlettestnetbanx_WAR_portlettestnetbanx__jsfBridgeViewId=%2Fviews%2Fview3.xhtml
Eric Soucy, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
It works I did it like this :

FacesContext fCtx = FacesContext.getCurrentInstance();
        PortletRequest req = (PortletRequest) fCtx.getExternalContext().getRequest();
        ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
        Layout layout = themeDisplay.getLayout();
        PortletDisplay portletDisplay= themeDisplay.getPortletDisplay();
        String portletId = PortalUtil.getPortletId(req);
        com.liferay.portal.kernel.portlet.LiferayPortletURL myActionURL  = PortletURLFactoryUtil.create(req, portletId, themeDisplay.getPlid(),        PortletRequest.RENDER_PHASE);
      
       myActionURL.setParameter("_jsfBridgeViewId", "/views/view3.xhtml");

thumbnail
Neil Griffin, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

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

Thanks for posting your solution. You might also be able to do it with fewer lines of code by using the standards-based JSF API, Portlet API, and Bridge API, like this:

FacesContext facesContext = FacesContext.getCurrentInstance();
MimeResponse mimeResponse = (MimeResponse) facesContext.getExternalContext.getResponse();
PortletURL renderURL = mimeResponse.createRenderURL();
renderURL.setParameter(Bridge.FACES_VIEW_ID_PARAMETER, "/views/view3.xhtml");


Kind Regards,

Neil
Eric Soucy, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
When I try your solution (which seems better than mine btw) i get the following error

15:47:37,170 ERROR [http-bio-8443-exec-16][status_jsp:750] com.liferay.portal.kernel.portlet.PortletContainerException: javax.portlet.faces.BridgeException: javax.portlet.faces.BridgeException: javax.faces.FacesException: #{paiementBean.submitPayment}: java.lang.ClassCastException: com.liferay.portlet.ActionResponseImpl cannot be cast to javax.portlet.MimeResponse
com.liferay.portal.kernel.portlet.PortletContainerException: javax.portlet.faces.BridgeException: javax.portlet.faces.BridgeException: javax.faces.FacesException: #{paiementBean.submitPayment}: java.lang.ClassCastException: com.liferay.portlet.ActionResponseImpl cannot be cast to javax.portlet.MimeResponse
at com.liferay.portlet.PortletContainerImpl.processAction(PortletContainerImpl.java:113)
thumbnail
Neil Griffin, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

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

Are you programmatically constructing the URL during the ACTION_PHASE of the portlet lifecycle for a particular reason? For example, perhaps you are doing a redirect.

Normally URL construction is done during the RENDER_PHASE, which is why you are seeing the ClassCastException.

Kind Regards,

Neil
Eric Soucy, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
yes that is exactly it, I need to do a redirect.
so is my proposed solution the way to go ?

Thanks
thumbnail
Neil Griffin, geändert vor 9 Jahren.

RE: deep linking inside jsf portlet from outside

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

If you are including the return URL as a parameter on the redirect URL, then yes I think you would need to stick with the solution you came up with. The Portlet API does not provide a way for MimeResponse.create*() methods to be used in your use-case.

Kind Regards,

Neil