如何在应用程序名称后隐藏JSF URL? [英] how to Hide JSF URL after the application name?

查看:124
本文介绍了如何在应用程序名称后隐藏JSF URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jsf应用程序,我想隐藏网址,并在网页之间切换时只保留网址中应用程序的名称。

i have a jsf application and i want hide the url and keep just the name of application in URL while swiching between pages .

这就是我拥有的网址:

thats the url that i have :

> http://localhost:8080/PlanificationDrapageWeb/faces/admin/adminHome.xhtml
> http://localhost:8080/PlanificationDrapageWeb/faces/cuisson/Home.xhtml

这就是我的意思想永远拥有:

and thats what i want always have :

> http://localhost:8080/PlanificationDrapageWeb/

我怎样才能得到这个结果?

how can i get this result ??

推荐答案

正如MaVRoSCy所说,您可以使用Prettyfaces重写您的URL。他们的文档非常有用且非常清晰。以下是要遵循的步骤(没有Maven依赖关系方法):

1)根据您的JSF版本下载最新的jar并将其放入项目类路径中。

2)添加以下内容 web.xml

As MaVRoSCy said you can use Prettyfaces to rewrite your URLs. Their docs are very useful and very clear. Here are steps to follow (without Maven dependencies approach):
1) Download latest jar depending on your JSF version and put it in your project classpath.
2) Add following to 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下创建 a file: pretty-config.xml 将定义你的漂亮面部映射,如下所示:

3) Create under WEB-INF a file: pretty-config.xml that will define your prettyfaces mappings, like this one:

<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>

4)现在在你的定义结果时托管bean,你应该返回漂亮:idOfURLMapping 。例如: pretty:accueil 将重定向到上面的第一个定义页面,通常会显示 http:// localhost:8080 / PlanificationDrapageWeb / 作为URL。

最后,请注意,只有当它是功能要求时才应使用它。否则我会使用没有扩展名的URL,如BalusC所提到的(他的方法或者你想要高级的Prettyfaces功能)。

编辑

似乎Prettyfaces没有为这种情况而努力。很抱歉你浪费时间。

现在我建议另一个可能的解决方案,因为BalusC的答案被删除了。

1)你创建一个新的会话范围的托管bean,让我们称之为: PageManagedBean

4) Now when defining outcome in your managed beans, you should return pretty:idOfURLMapping. For example: pretty:accueil will redirect to the first defined page above and normally it would display http://localhost:8080/PlanificationDrapageWeb/ as URL.
Finally, notice that you should use this only if it's a functional requirement. Otherwise I would use URLs without extensions as BalusC mentioned (his method or if you want advanced Prettyfaces functionalities).
EDIT
It seems that Prettyfaces does not work for this situation. Sorry for your time wasting.
Now I would suggest another possible solution, since BalusC's answer was deleted.
1) You create a new managed bean of session scope, let's call it: PageManagedBean:

public class PageManagedBean {
  private String includedPage = "/pages/accueil.xhtml";
  //Setters and getters
}

2)创建主布局页面(Facelets模板化):

2) Create a master layout page (Facelets templating):

<!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值即可。

Now when you want to change page, you just change PageManagedBean.includedPage value.

这篇关于如何在应用程序名称后隐藏JSF URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆