我是 jsf 的新手。
我基本上有 4 个 jsf 文件。
1) 菜单.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>
包括1.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>
包括2.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>
包括3.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>
内容.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>
我的豆类是
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";
}
}
预期的行为是,当我单击 Include1 链接时,它会在中心框架中显示 include1.jsf,对于 Include2 链接也是如此。
但是,Include1 的绝对路径不起作用。如果我用相对路径替换绝对路径,那么它工作正常。有人可以帮我理解为什么会这样吗?这是预期的行为还是我做错了什么。
谢谢