Partial JSF Rendering Components

on how to do partial rendering (divs), including various source files (with panels and components). Depending on the actions of the menu. If you understand the JSF phases correctly, the View is rebuilt during the Render Response, the last phase. And if I have events and actions, they will be called during the application-application phase, the phase is earlier.

All I want to do is set the xhtml inclusion page for a specific menu command via ajax before the View is re-rendered. But ui: include is always called before a menu action. I tried with RichFaces 4 (a4j: Param, rich: panels, etc.) and the standard JSF 2.0 (e: Param, h: panelGroup) component, but the Ui: key always includes an invoked action.

What to do to process the action menu (to set the inclusion page) before calling ui: include ?

PS. This should be a standard step, instead of including static content. But I find very few examples of this on the net ?!

Menu.xhtml

<rich:toolbar itemSeparator="line">
...
<rich:dropDownMenu mode="ajax">

    <f:facet name="label">
                <h:panelGroup>
                    <h:outputText value="Menu 1" />
                </h:panelGroup>
            </f:facet>
            <rich:menuItem id="newActivityMenu" action="#{navigationBean.menuAction}" render="content" label="New">
                <a4j:param id="newActivityParam" name="includeContentPage" value="/user/Create.xhtml" />
            </rich:menuItem>
...

NavigationBean.Java

    @ManagedBean
@RequestScoped
public class NavigationBean {

    public String menuAction() {
    String param = JsfUtil.getRequestParameter("includeContentPage");
    this.includedContentPage = param;
    JsfUtil.log(this, "Including Content Page : " +param);

    FacesContext.getCurrentInstance().renderResponse();
    return "";
}

public String getIncludedContentPage() {
    if(includedContentPage == null)
        return "";
    else if(!includedContentPage.endsWith(".xhtml"))
        includedContentPage += ".xhtml";
    JsfUtil.log(this, "Get Content Page : " +includedContentPage);
    return includedContentPage;
    }

layoutClient.xhtml

...
<ui:define name="top">
        <ui:include src="/resources/viewComponents/menuTop.xhtml"/>
    </ui:define>
    <ui:define name="content">                
        <ui:include src="#{navigationBean.includedContentPage}"/>
    </ui:define>
...

masterLayout.xhtml (added)

...
<h:body>
    <div id="top" >
        <ui:insert name="top">Top Default</ui:insert>
    </div>
    <div id="left">
        <ui:insert name="left">Left Default</ui:insert>
    </div>
         <ui:insert name="content">Content Default</ui:insert>
    </h:body>
..
+3
1

, layoutClient.xhtml, , layoutClient.xhtml , , , . , template.xhtml. , , , :

template.xhtml

...
<ui:insert name="top">
    <ui:include src="/resources/viewComponents/menuTop.xhtml"/>
</ui:insert>
...
<ui:insert name="content" />
...

, ( ) , .

, layoutClient.xhtml, , , :

page1.xhtml

<ui:composition template="template.xhtml">
    ...
    <ui:define name="content">
        <p>This is a page that defines some content and also includes my menu that it inherits from template.xhtml</p>
    </ui:define>
    ...
</ui:composition>

page2.xhtml

<ui:composition template="template.xhtml">
    ...
    <ui:define name="content">
        <p>This is another page that defines some content and also includes my menu that it inherits from template.xhtml</p>
    </ui:define>
    ...
</ui:composition>

.

menuAction() page1.xhtml page2.xhtml. , renderResponse() a4j:param!

+2

All Articles