1

I am new to jsf.

I have basically 4 jsf files.

1) menu.xhtml

<h:html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"    
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:p="http://primefaces.org/ui">

 <h:head>

<h:body>

  <p:layout fullPage="true">
   <p:layoutUnit position="north" style="min-width: 300px;" gutter="0">
    <ui:insert name="header">
     <ui:include src="../../layout/header.xhtml" />
    </ui:insert>
   </p:layoutUnit>

   <p:layoutUnit position="center" style="border:none;" gutter="0">
    <p:panel id="content" style="background : transparent; border : 0;">
     <ui:include src="content.xhtml" />
    </p:panel>
   </p:layoutUnit>

   <p:layoutUnit position="west" collapsible="true" gutter="6"  >
   <h:panelGroup id="menu" layout="block">
   <h:form>
    <ul>
     <li><p:commandLink value="goto-include1" action="#{bean.doAction1}" update=":mainContent" ajax="true" /></li>
     <li><p:commandLink value="goto-include2" action="#{bean.doAction2}" update=":mainContent" ajax="true" /></li>
    </ul>
   </h:form>
  </h:panelGroup>
   </p:layoutUnit>

   <p:layoutUnit position="south" style="min-width: 300px;" gutter="0">
    <div id="footer" class="ui-widget ui-widget-header">
     <ui:include src="../../layout/footer.xhtml"></ui:include>
    </div>
   </p:layoutUnit>

  </p:layout>`enter code here`


 </h:body>
</f:view>
</h:html>

Include1.jsp

<ui:composition xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
        <h:outputText value="Include1"/>
</ui:composition>

Include2.jsp

<ui:composition xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
        <h:outputText value="Include1"/>
</ui:composition>

Include3.jsp

<ui:composition xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
        <h:outputText value="Include1"/>
</ui:composition>

Content.jsp

<ui:composition xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
    <h:panelGroup id="mainContent" layout="block">
        <ui:include src="#{bean.page}.xhtml" />
    </h:panelGroup>
</ui:composition>

My bean class is as

package com.assia.dslo.expresse.gui.component.pe;

import java.io.File;
import java.io.Serializable;

public class Bean implements Serializable {

    private String page = "include3";
    public String getPage() {
        return page;
    }
    public void setPage(String page) {
        this.page = page;
    }
    private static final long serialVersionUID = -802772877129109794L;

    public void doAction1() {
        this.page = "expresse/pe/include1.xhtml";
    }

    public void doAction2() {
        this.page = "include2";
    }
}

The intended behavior is that when I click on the Include1 link , it displays the include1.jsf in the center frame and similarly for the Include2 link.

However, the absolute path for Include1 does not work. If I replace the absolute path by a relative path,then it works fine. Can somebody help me understand why this happens ? Is this an expected behavior or there is something wrong that I am doing .

Thanks

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
rush00121
  • 185
  • 1
  • 5
  • 13
  • Absolute path works fine. Do your absolute path start with a slash (eg `/expresse/pe/include1.xhtml`) ? Absolute path start from the `webapp` dir, for a file stores in `src/main/webapp/a/b/c.xhtml` (I assume you use Maven), the absolute path will be `/a/b/c.xhtml` – Nicolas Labrot Feb 20 '13 at 06:44

1 Answers1

2

An absolute path starts with a slash / which will take your to the root. Your path does not start with a slash / and is therefore not an absolute path at all.

Fix it accordingly. Replace

this.page = "expresse/pe/include1.xhtml";

by

this.page = "/expresse/pe/include1.xhtml";

Unrelated to the concrete problem, it's recommend to put files which are not supposed to be directly publicly accessible inside the /WEB-INF folder. Otherwise the enduser would get a partial/broken page when entering/guessing its path in the browser's address bar.

this.page = "/WEB-INF/expresse/pe/include1.xhtml";

Do the same for all your other include and template files. Don't forget to replace their relative paths by absolute paths starting with /WEB-INF.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Yes, you are right. This works. This is an extension of your solution to a previous problem in stackoverflow. Thanks for the help – rush00121 Feb 20 '13 at 19:31