我有一个jsf应用程序,我想隐藏网址,并在页面之间切换时只保留URL中的应用程序名称.
这就是我拥有的网址:
> http://localhost:8080/PlanificationDrapageWeb/faces/admin/adminHome.xhtml
> http://localhost:8080/PlanificationDrapageWeb/faces/cuisson/Home.xhtml
Run Code Online (Sandbox Code Playgroud)
这就是我想要的总是:
> http://localhost:8080/PlanificationDrapageWeb/
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个结果?
正如 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>
Run Code Online (Sandbox Code Playgroud)
3)在一个文件下创建WEB-INF:pretty-config.xml它将定义你的漂亮脸映射,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
outcome4) 现在在托管 bean 中定义时,您应该返回pretty:idOfURLMapping. 例如:pretty:accueil将重定向到上面定义的第一个页面,通常它会显示http://localhost:8080/PlanificationDrapageWeb/为 URL。
最后,请注意,只有在功能要求时才应该使用它。否则我会使用不带扩展名的 URL,如 BalusC 提到的(他的方法或者如果您想要高级 Prettyfaces 功能)。
编辑
看起来 Prettyfaces 不适用于这种情况。很抱歉浪费您的时间。
现在我建议另一种可能的解决方案,因为 BalusC 的答案已被删除。
1) 创建一个新的会话范围托管 bean,我们将其命名为PageManagedBean:
public class PageManagedBean {
private String includedPage = "/pages/accueil.xhtml";
//Setters and getters
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
现在,当您想要更改页面时,只需更改 PageManagedBean.includedPage 值即可。
| 归档时间: |
|
| 查看次数: |
9163 次 |
| 最近记录: |