2010-10-15 95 views
0

我有一个页面index.jsf,我用ui:include包含页眉和页脚,我想在内容中动态查看,这意味着当用户点击注册链接时只是内容改变页眉和页脚没有改变如何在一个页面中创建动态视图

我像我的代码示例是:

<ui:include render="#{mybean.include}"/> 

和支持豆我的代码:

public void getInclude(){ 
    if("page" == a){ 
     return "a.jsf"; 
    } 
    else if("page" == b) { 
    return "b.jsf"; 
    } 
} 

,我用漂亮的URL例如 老办法JSF页面将显示网址

http://localhost/index.jsf?page=a or http://localhost/index.jsf?page=b 

,但我想用漂亮的网址,而不是旧的方式,例如:

http://localhost/index/a 

我怎么能做到这一点(这意味着使用漂亮的面孔,以及如何我) 我可以在这里解释上述问题 而不是以上我使用if(“page”= a)如果我使用旧的方式粘贴参数url http://loalhost/index.jsf?page=a 但如果我使用pretter url或漂亮的脸上什么我会为if-else语句做些什么? 如果(?= A)

2问题,请帮我三江源

========================================================== 

现在我成立了漂亮的面孔和很好地工作,但我不知道我怎样才能从参数Prettyfaces,在漂亮,配置.XML我是配置页面如下:

主页(在那里含量的变化动态)

<url-mapping id="mainpage"> 
<pattern value="/home" /> 
<view-id>/faces/main.xhtml</view-id> 
</url-mapping> 

第1页

<url-mapping id="mainpage"> 
<pattern value="/home/#{page:content1}" /> 
<view-id>/faces/content1.xhtml</view-id> 
</url-mapping> 

页2

<url-mapping id="mainpage"> 
<pattern value="/home/#{page:content2}" /> 
<view-id>/faces/content2.xhtml</view-id> 
</url-mapping> 

在一个页面中我使用的用户界面:包括动态子视图

<ui:include src=#{bean.includePage}/> 

我的豆已经为得到一个方法包括页面

public String getIncludePage(){ 
     if(page == null){ 
     return "content.xhtml"; 
     } 
     else if (page.equals(content1)){ 
     return "content1.xhtml"; 
     } 
     else if (page.equals(content2)){ 
     return "content2.xhtml; 
     } 
} 

但我无法在一页中更改动态页面浏览内容

+0

我会回答“使用PrettyFaces”。但你显然已经意识到这一点。你有什么问题呢?到目前为止你做了什么以及在实现PrettyFaces的同时你在哪一步做了什么? – BalusC 2010-10-15 10:43:06

+0

嗨Balus我是编辑我的问题,你能帮我吗?谢谢 – MYE 2010-10-17 04:01:07

+0

请帮助我! :( – MYE 2010-10-17 08:26:15

回答

0

如果我正确理解你的问题,你的问题与PrettyFaces无关。

想要结束共享相同页眉和页脚的不同页面是否正确?在这种情况下,您应该真正了解有关Facelets的模板,因为这完全是它的用例。

这里就Facelets的是如何工作的一个简单的例子:

template.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:ui="http://java.sun.com/jsf/facelets"> 
<head> 
    <title> 
    <ui:insert name="title" /> 
    </title> 
    <link rel="stylesheet" type="text/css" href="./css/main.css"/> 
</head> 

<body> 

<div id="center"> 
    <ui:insert name="title" /> 
    <hr /> 
    <ui:insert name="content" /> 
</div> 

</body> 

</html> 

some-page.xhtml

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

<ui:composition template="/template.xhtml"> 
    <ui:define name="title">My Page Title</ui:define> 
    <ui:define name="content"> 

    <p> 
     This is the main content area 
    </p> 

    </ui:define> 
</ui:composition> 
</html> 

我建议阅读Facelets fits JSF like a glove。这是关于Facelets的一篇非常棒的文章。