Fórum

Loading different JSF pages from outside the JSF portlet

Jorge Serrano, modificado 11 Anos atrás.

Loading different JSF pages from outside the JSF portlet

New Member Postagens: 8 Data de Entrada: 06/09/12 Postagens Recentes
Hi all,

I wonder if there is any way to load different JSF pages in the same portlet depending on which page of the portal the user is. I have a portal with a navigation panel with different sections. On every page I have a JSF portlet and I want to load the JSF page from the section that is selected from the navigation panel.

For example, I have the pages page1 and page2 in the portal. In the page1 I want the portlet to load the page page1.xhtml and in the page2, load page2.xmtml

I have check that I can navigate in different pages JSF within the JSF portlet but not now from outside the JSF portlet.

Does Liferay give some facility to do this?
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: Loading different JSF pages from outside the JSF portlet

Liferay Legend Postagens: 14914 Data de Entrada: 02/09/06 Postagens Recentes
The application container itself will block you from importing pages in another web application directory.

If you roll your JSF portlets into a single deployable artifact (a single war w/ multiple portlets), you can import and use the other portlet's JSF pages.
thumbnail
Neil Griffin, modificado 11 Anos atrás.

RE: Loading different JSF pages from outside the JSF portlet (Resposta)

Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens Recentes
David is right. Along the lines of his suggestion, here is some additional information that might be helpful:

First, your Facelet view for Portlet VIEW mode could do something like this:

<ui:include src="#{backingBean.faceletComposition}" />


And then in your backing bean:

@ManagedBean
@RequestScoped

public class BackingBean {

    public String getFaceletComposition() {

        LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
        ThemeDisplay themeDisplay = liferayFacesContext.getThemeDisplay();
        Layout portalPage = themeDisplay.getLayout();
        String portalPageName = layout.getName(Locale.US);
        return portalPageName + ".xhtml";
    }
}
Jorge Serrano, modificado 11 Anos atrás.

RE: Loading different JSF pages from outside the JSF portlet

New Member Postagens: 8 Data de Entrada: 06/09/12 Postagens Recentes
Hi David and Neil and thanks for your responses,

I think I have not explained it well. What I wanted is to navigate to a particular JSF page depending on what portal page the user is. Finally I made it through a JSF PhaseListener, which gets the portal page from PortletRequest, and on that basis, it loads the corresponding JSF page in JSF Portlet

It works for me, what do you think?


public class PortletNavigationPhaseListener implements PhaseListener {

	public void afterPhase(PhaseEvent event) {
		
		PhaseId phaseid = event.getPhaseId();
               if (phaseid == PhaseId.RESTORE_VIEW) {
			FacesContext facesContext = event.getFacesContext();
			ExternalContext externalContext = facesContext.getExternalContext();
			PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
			
			ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
	    	        Layout layout = themeDisplay.getLayout();
	    	        String pagina = layout.getFriendlyURL();

	    	        if(pagina.equals("/vista2")) {
				facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, "vista2");
			}
                        if(pagina.equals("/vista3")) {
				facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, "vista3");
			}
	    	
                 }
	}
thumbnail
Neil Griffin, modificado 11 Anos atrás.

RE: Loading different JSF pages from outside the JSF portlet

Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens Recentes
The PhaseListener approach will work, but there is a chance it will be less performant because the PhaseListener will execute every single time the JSF lifecycle executes (not just on the initial page load). For example, the PhaseListener executes even when doing a simple Ajax update with f:ajax
Jorge Serrano, modificado 11 Anos atrás.

RE: Loading different JSF pages from outside the JSF portlet

New Member Postagens: 8 Data de Entrada: 06/09/12 Postagens Recentes
Ok thanks, you're right. I will also try your solution ;-)