Question

I'm using JSF 2.1 on Tomcat6 with the el2.2 libraries.

I have created a template layout with a header, menubar and footer common to all pages, with only the content changing. Each section is in its own div tags. Everything works fine and the menubar links navigate correctly to new pages using faces-config navigation rules.

I've now created a content page which holds dynamically created UIComponents. When the view renders, the panelgrid with one item apears correctly, but all the menu items no longer work!

If I remove the panelgrid tag from the xhtml and refresh then the menu items work correctly again. The ONLY difference in the generated HTML in this case is the presence/absence of the table tag for the panelgrid.

In the following examples I've stripped it down to a single HtmlPanelGrid with a single child.

My Bean: (All BaseBean does is implement Serializable).

package org.gwl.chart;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlOutputLabel;
import javax.faces.component.html.HtmlPanelGrid;

import com.praxism.iims.web.BaseBean;

@ManagedBean
@SessionScoped
public class DashBacker extends BaseBean {

    private static final long serialVersionUID = -894246439580172432L;

    HtmlPanelGrid _dash;

    public DashBacker() {
    }

    @PostConstruct
    public void init() {
        _dash = new HtmlPanelGrid();
        _dash.setColumns(3);
        _dash.setId("dashboard");

        HtmlOutputLabel label1 = new HtmlOutputLabel();
        label1.setId("label1");
        label1.setValue("Label 1");
        _dash.getChildren().add(label1);
    }

    public HtmlPanelGrid getDash() {
        return _dash;
    }
}

My content xhtml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:iims-chart="http://java.sun.com/jsf/composite/components/chart">
    <ui:composition>    
        <h:outputText styleClass="h1" value="#{msgs_dash.heading}"/>
        <h:messages errorClass="errorMessage" infoClass="infoMessage" warnClass="warnMessage"/>
        <h:panelGrid binding="#{dashBacker.dash}" />
    </ui:composition>
</html>

My MenuBar xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
    <ui:composition>
        <h:form id="menuBarFrm" styleClass="my-menubar">
            <p:menubar>
                <p:menuitem rendered="#{request.isUserInRole('user')}" value="Home" action="home"/>
                <p:submenu rendered="#{request.isUserInRole('user')}" label="Help">
                    <p:menuitem rendered="#{request.isUserInRole('user')}" value="About" action="about"/>
                </p:submenu>
            </p:menubar>
        </h:form>
    </ui:composition>   
</html> 

And finally, my layout template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title><ui:insert name="windowTitle">DEFAULT_TITLE</ui:insert></title>
    </h:head>
    <h:body>
        <div id="layout-header">
            <ui:insert name="header">No define for "header"!</ui:insert>
        </div>
        <div id="layout-menubar">
            <ui:insert name="menubar">No define for "menu"!</ui:insert>
        </div>
        <div id="layout-content">
            <div id="layout-scrollable">
                <div id="layout-margin">
                    <ui:insert name="content">No define for "content"!</ui:insert>
                </div>
            </div>
        </div>
        <h:messages/>
        <div id="layout-footer">
            <ui:insert name="footer">No define for "content"!</ui:insert>
        </div>
    </h:body>
</html> 
Was it helpful?

Solution

You can not store components in anything higher than the request scope.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top