MaVRoSCy が言ったように、Prettyfaces を使用して URL を書き換えることができます。彼らのドキュメントは非常に役に立ち、非常に明確です。従うべき手順は次のとおりです(Maven依存関係アプローチなし):
1)JSFバージョンに応じて最新のjarをダウンロードし、プロジェクトのクラスパスに配置します。
2) に以下を追加web.xml
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
3)WEB-INF
ファイルの下に作成: 次pretty-config.xml
のように、prettyfaces マッピングを定義します。
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.0
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.0.xsd">
<url-mapping id="accueil">
<pattern value="/" />
<view-id value="/path-to-yourpage.xhtml" />
</url-mapping>
<url-mapping id="error">
<pattern value="/" />
<view-id value="/tpath-to-yourpage2.xhtml" />
</url-mapping>
</pretty-config>
outcome
4)マネージド Bean で定義するときは、 を返す必要がありますpretty:idOfURLMapping
。例:pretty:accueil
上記の最初に定義されたページにリダイレクトされ、通常はhttp://localhost:8080/PlanificationDrapageWeb/
URL として表示されます。
最後に、これは機能要件である場合にのみ使用する必要があることに注意してください。それ以外の場合は、BalusC が述べたように、拡張子のない URL を使用します (彼の方法、または高度な Prettyfaces 機能が必要な場合)。
編集
Prettyfaces はこの状況では機能しないようです。時間を無駄にして申し訳ありません。
BalusCの回答が削除されたため、別の解決策を提案します。
1) セッション スコープの新しいマネージド Bean を作成します。それを呼び出しましょう: PageManagedBean
:
public class PageManagedBean {
private String includedPage = "/pages/accueil.xhtml";
//Setters and getters
}
2) マスター レイアウト ページ (Facelets テンプレート) を作成します。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.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">
<h:head>
<ui:insert name="head"></ui:insert>
</h:head>
<h:body>
<div class="pagewidth">
<ui:include src="shared/header.xhtml"/>
<!-- Content -->
<div class="page_content">
<div class="page_content_inner">
<div class="container">
<ui:include id="pageLivre" src="#{pageManagedBean.includedPage}"/>
</div>
</div>
</div>
<div class="page_content_footer"/>
<ui:include src="shared/footer.xhtml"/>
</div>
</h:body>
ページを変更したい場合は、PageManagedBean.includedPage の値を変更するだけです。