【问题标题】:How to create dynamic view in one page如何在一页中创建动态视图
【发布时间】:2011-04-25 21:01:18
【问题描述】:

我有一页 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 来做什么?) 我可以在这里解释上述问题 如果我使用旧方式粘贴参数 url http://loalhost/index.jsf?page=a,而不是上面我使用 if("page"=a) 但是如果我使用更漂亮的 url 或漂亮的面孔,我会为 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>

第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 作为动态子视图

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

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

【问题讨论】:

  • 我会回答“使用 PrettyFaces”。但是你显然已经意识到了这一点。你有什么问题?在实施 PrettyFaces 的过程中,您目前做了哪些工作?在哪个步骤上卡住了?
  • 嗨,Balus,我正在编辑我的问题,请您帮帮我!谢谢
  • 我不确定漂亮的面孔部分,但您知道== 不会按值比较字符串而是按引用比较字符串?要比较两个字符串(与所有其他对象一样)的值,请使用 equals() 方法。
  • 嗨 Balus 我在我的代码中修复了它,我认为我在某个地方错了,我试图阅读教程,但不清楚,我会尝试非常感谢你!尊重你!
  • 我在这里解决了这个问题:ibm.com/developerworks/java/library/j-facelets

标签: jsf prettyfaces


【解决方案1】:

如果我正确理解了您的问题,那么您的问题与 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 的非常棒的文章。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 2017-07-05
    • 2023-01-03
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 2016-09-18
    相关资源
    最近更新 更多