如何在一页中创建动态视图

发布于 2024-09-27 18:03:39 字数 2056 浏览 3 评论 0 原文

我有一页index.jsf,我使用 ui:include 包含页眉和页脚,我想动态查看内容,这意味着当用户单击注册链接时,仅内容更改页眉和页脚没有更改

我的图像我的代码示例是:

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

在支持 bean 中,我的代码将:

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

并且我使用漂亮的 url 示例 以旧的方式 jsf 页面将显示 url

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

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

http://localhost/index/a

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

2个问题请帮助我谢谢

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

现在我设置了漂亮的面孔并且工作良好,但我不知道如何从 Prettyfaces 获取参数,在 Pretty-config.xml 中我的配置页面如下:

主页(内容在那里更改动态)

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

第一页中的第一页

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

第二页

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

我使用 ui:include 作为动态子视图

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

我的 bean 有一种获取包含页面的方法

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

但我无法更改一页中的动态页面视图内容

i have one page index.jsf, i was use ui:include for include header and footer,i want to dynamic view in content, it mean when user click on register link just content change header and footer didn't change

i image my code sample is:

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

and in backing bean my code will :

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

and i to use pretty url example
in old way jsf page will display url

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

but i want use pretty url instead of old way, example:

http://localhost/index/a

how can i do it (it mean using pretty faces and how i can use if-else for what?)
i can explain above question here
instead of above i use if("page"=a) if i use old way paste parameter url http://loalhost/index.jsf?page=a
but if i use pretter url or pretty faces what would i do for if-else statement?
if(?? = a)

2 question please help me thankyou

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

Now i set up pretty faces and work well but i dont know how can i get parameter from Prettyfaces, in Pretty-config.xml i was config page follow:

Main page ( content change dynamic in there)

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

Page1

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

page 2

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

in page one i use ui:include for dynamic subview

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

my bean have one method for get include page

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

But i can't change dynamic page view content in one page

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2024-10-04 18:03:39

如果我正确理解你的问题,你的问题与 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 像手套一样适合 JSF。这是一篇关于 Facelets 的非常棒的文章。

If I understood your question correctly your problem has nothing to do with PrettyFaces.

Is it correct that you want to end up with different pages which share the same header and footer? In this case you should really learn about templating with Facelets because this is exactly an usecase for it.

Here a short example on how Facelets work:

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>

I recommend to read Facelets fits JSF like a glove. It's an really great article on Facelets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文