开发者

How to create dynamic view in one page

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜