JSF的URL扩展,重写工具 PrettyFaces

注意:路径配置,比如 /xxx/user 配置为 /xxx/user/ ,可能引发 shiro 控制出错.引发其他一些未知的BUG.这个东西...还是有很多BUG的.一般情况,最后不要以"/"结束.

PrettyFaces是一个JSF1.2和JSF2.0的扩展,是一个开源基于过滤器(Filter)的Servlets扩展.用来创建便于书签收藏、漂亮的网址。 PrettyFaces优雅的解决了这个问题,包括诸如功能:网页装载行动,无缝的跟faces的导航整合,动态视图的ID分配和管理参数分析,无需配 置,兼容其他JSF框架。PrettyFaces优雅地解决了“RESTful URL” 问题,包括这样一些特性如:

  1. URL Rewriting — Replace ugly URLs: “/faces/page.jsf” with pretty, SEO-friendly, human URLS: “/optimized/page/”; The client browser never sees your original URLs, even in the source-HTML
  2. Dynamic view IDs — Now with dynamic view ID mapping for URLs (through El method expressions,) you can show different views based on run-time conditions, effectively de-coupling the URL from the JSF view.
  3. Page-load actions — Call one or more action-methods, at one or more phases, before rendering a view.
  4. Managed parameter parsing — HTTP parameters parsed from URLs are stored in managed beans, simply get a reference to your parameter bean for easy access from other Java classes.
  5. Navigation by ID — Define your page IDs in one place, reference them easily in action-methods and components, using standard JSF navigation techniques.
  6. Integrated validation — For URL and query-parameters, able to re-use existing JSF validator objects.
  7. Easy to configure — Requires absolutely minimal configuration; may be enabled using XML or annotations.
该项目主页: http://ocpsoft.org/prettyfaces/

Get Started, it’s easy! (3 steps)

1. Include PrettyFaces in your Project

You may either use Maven (recommended) to include PrettyFaces in your project, or you can download the distribution ZIP file directly.

If you are upgrading from PrettyFaces 3.x, note that all functionality is backwards compatible, but you may wish to review the migration guide to learn about new features made available in the latest releases.

POM.XML

<!-- for JSF 2.x -->
<dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-servlet</artifactId>
    <version>2.0.12.Final</version>
</dependency>
<dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-config-prettyfaces</artifactId>
    <version>2.0.12.Final</version>
</dependency>

2. Create pretty-config.xml

This is where you will create URL mappings between external URL patterns and your internal view files, Servlets, and other resources. Be sure to replace the mapping below with a mapping that matches your application.

/WEB-INF/pretty-config.xml

<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
                      http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">

	<url-mapping id="login">
		<pattern value="/login" />
		<view-id value="/legacy/user/login.jsp" />
	</url-mapping>

</pretty-config>

Add mappings to your configuration

This part is all up to you! You’ll need to figure out which URLs in your application you want to “prettify” – so check out the documentation for details on how to fully utilize the PrettyFaces URL-mapping system.

Additionally, be sure to check out the Rewrite examples or reference manual to learn more about Rewrite, and the powerful options it offers beyond the PrettyFaces configuration module.


<url-mapping id="view-user">
	<pattern value="/user/#{username}" />
	<view-id value="/user/view.xhtml" />
</url-mapping>

<!-- Maps "/user/#{username}" to the URL "/user/view.xhtml?username=value" -->

3. Run your application!

You should now be ready to go! PrettyFaces is installed and your first URL-mapping has been created. If everything has been done correctly, you should see PrettyFaces log a message confirming that setup was successful.

你可能感兴趣的:(JSF的URL扩展,重写工具 PrettyFaces)