prettyfaces的URL配置

来源:互联网 发布:时时彩后一分析软件 编辑:程序博客网 时间:2024/05/17 03:25

Named path parameters

<pattern value="/store/#{ cat }/" />
String category = request.getParameter("cat");

EL-injected path parameters

<pattern value="/store/#{ bean.location }/" />
@Named("bean")@RequestScopedpublic class CategoryBean {private String category;/* Getters & Setters */}
Notice, you can specify both a name and an EL value-injection for the same path-parameter.
<pattern value="/store/#{ cat : bean.location }/" />

Restrict what Path Parameters will accept (Custom regex patterns)

<url-mapping id="archives">  <pattern value="/#{ ///d{4}/ year }/#{ ///d{2}/ month }/" />  <view-id>/faces/blog/archives.jsf</view-id> </url-mapping>
<pattern value="/#{ /[a-z]+/ blogger }/#{ ///d+/ postId }/" />

Inherit from a parent URL-mapping

<url-mapping parentId="store" id="category"> ... </url-mapping>
<url-mapping id="store">    <pattern value="/store/" />    <~-- Result: /store/ -->   <view-id value="/faces/shop/store.jsf" /></url-mapping><url-mapping parentId="store" id="category">    <pattern value="/#{category}" />    <~-- Result: /store/#{category} -->   <view-id value="/faces/shop/category.jsf" /> </url-mapping><url-mapping parentId="category" id="item">    <pattern value="/#{item}" />    <~-- Result: /store/#{category}/#{item} -->   <view-id value="/faces/shop/item.jsf" /> </url-mapping>

Dynamic view-IDs (DynaView) 这里可以做权限检查

<url-mapping id="home"><pattern value="/home/" /><view-id> #{bean.getViewPath} </view-id></url-mapping>
@Named("bean")@RequestScopedpublic class HomeBean {@Inject CurrentUser user;public String getViewPath() {if ( user.isLoggedIn() ){return "/faces/home/home.jsf";}return "/faces/login.jsf";}}

Load data when accessing mapped URLs

<url-mapping id="viewItem">  <pattern value="/store/item/#{ iid : bean.itemId }/" />  <view-id>/faces/shop/item.jsf</view-id>   <action>#{bean.loadItem}</action>              //这个就是相当于 页面数据加载初始化方法</url-mapping>

Invoking navigation from a page-action

<url-mapping id="viewItem">  <pattern value="/store/item/#{ iid : bean.itemId }/" />  <view-id>/faces/shop/item.jsf</view-id>   <action>#{bean.loadItem}</action></url-mapping>
@Named("bean")@RequestScopedpublic class CategoryBean {public String loadItem() {if ( itemId != null ) {this.item = items.findById(itemId);return null;                                                //return null  继续访问页面}return "failure";                                                //导向到一个新的地址,这就像之前用到的 动态 view-id一样}}

 

 

原创粉丝点击