留言板

Loading different JSF pages from outside the JSF portlet

Jorge Serrano,修改在11 年前。

Loading different JSF pages from outside the JSF portlet

New Member 帖子: 8 加入日期: 12-9-6 最近的帖子
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,修改在11 年前。

RE: Loading different JSF pages from outside the JSF portlet

Liferay Legend 帖子: 14917 加入日期: 06-9-2 最近的帖子
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,修改在11 年前。

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

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
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,修改在11 年前。

RE: Loading different JSF pages from outside the JSF portlet

New Member 帖子: 8 加入日期: 12-9-6 最近的帖子
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,修改在11 年前。

RE: Loading different JSF pages from outside the JSF portlet

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
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,修改在11 年前。

RE: Loading different JSF pages from outside the JSF portlet

New Member 帖子: 8 加入日期: 12-9-6 最近的帖子
Ok thanks, you're right. I will also try your solution ;-)