SlideShare a Scribd company logo
Christian Kaltepoth | ingenit GmbH & Co. KG
Beyond PrettyFaces
Einführung in Rewrite
URL-Rewriting
Wikipedia
A rewrite engine is software located in a
Web application framework running on a
Web server that modifies a web URL's
appearance.
This modification is called URL rewriting.
http://en.wikipedia.org/wiki/Rewrite_engine
Beispiel
http://www.onlineshop.de/b/ref=sa_m
enu_desk3?ie=UTF8&node=2193272340
http://www.onlineshop.de/elektronik
Sprechende RESTful URLs
http://www.javaserverfaces.org/news
http://jax.de/2013/sessions/
https://github.com/ocpsoft/rewrite/issues/87
http://stackoverflow.com/questions/tagged/jsf
Wozu das Ganze?
Vorteile
• Adressierbare Informationen
– Wo bin ich hier?
– "Vertrauen"
• Reload und Bookmarks
• Einfache HTML Links
– Lose Kopplung
• Technologieneutralität
SEO
• Keywords in URL
• Optimierung des Rankings
http://www.amazon.com/JavaServer-
Faces-2-0-Complete-
Reference/dp/0071625097
PrettyFaces
• JSF URL-Rewriting De-facto-Standard
• RESTful URLs
• Page Actions
• Einfache Rewrite Engine
• Dynamic Views
• Integration mit JSF Navigation
Warum Rewrite?
API Abhängigkeiten
Servlet-spezifisch
JSF-spezifisch
PrettyFaces
Beyond PrettyFaces - Einführung in Rewrite
Einschränkungen
• Mapping nur via Request Path
• Eingeschränkte Konfiguration via XML
• Annotation API „verbesserungswürdig“
• Konvertierung nur eingeschränkt
möglich
• Nicht besonders erweiterbar
Der Neuanfang
Was ist Rewrite?
Key Features
• Servlet basiertes Rewriting auf Basis
einer Rule-Engine
• Framework Integration
– JSF, CDI, Spring, Shiro, etc.
• Konfiguration: Java DSL + Annotations
• Fokus auf Erweiterbarkeit
• Open Source (Apache 2.0)
Begriffe
• Configuration:
– Sortierte Liste
von Rules
• Rule:
– Conditions
– Operations
– Priority
Rewriting Types
Inbound
Outbound
Inbound
GET /faces/home.xhtml HTTP/1.1
Host: www.acme.com
Connection: keep-alive
[....]
Outbound
<a href="/faces/home.xhtml">
Getting started
</a>
Java DSL
Warum?
• Typensichere Konfiguration
• Code Assist durch IDE
• Erweiterbar
• Geführte Konfiguration
• „Plain Java“
Java DSL
public class RewriteConfig extends HttpConfigurationProvider {
@Override
public Configuration getConfiguration(ServletContext ctx) {
// Konfiguration
}
@Override
public int priority() {
return 10;
}
}
ConfigurationBuilder
return ConfigurationBuilder.begin()
// Variante 1
.addRule()
.when( /* condition */ )
.perform( /* operation */ )
// Variante 2
.addRule( /* rule */ )
;
Initial Redirect
http://www.acme.com/
http://www.acme.com/faces/home.xhtml
Redirect
Beispiel: Initial Redirect
.addRule()
.when(
Direction.isInbound().and(Path.matches("/"))
)
.perform(
Redirect.permanent("/faces/home.xhtml")
)
Der erste Rewrite
http://www.acme.com/faces/home.xhtml
http://www.acme.com/home
Der erste Rewrite
.addRule()
.when(Direction.isInbound().and(
Path.matches("/home")))
.perform(Forward.to("/faces/home.xhtml"))
.addRule()
.when(Direction.isOutbound().and(
Path.matches("/faces/home.xhtml")))
.perform(Substitute.with("/home"))
Einfacher: Joins
.addRule(
Join.path("/home")
.to("/faces/home.xhtml")
)
Parameter
/faces/products.xhtml?category=books
/products/books
JSF 2.0 View Parameter
<f:metadata>
<f:viewParam name="category"
value="#{productListPage.category}" />
</f:metadata>
@Named
@RequestScoped
public class ProductListPage {
private String category;
}
Join mit Parametern
.addRule(
Join.path("/products/{category}")
.to("/faces/products.xhtml")
)
Demo
Annotations?
Einfacher Join
@Named
@RequestScoped
@Join(path = "/home",
to = "/faces/home.xhtml")
public class HomePage {
/* your code */
}
Parameter
/faces/products.xhtml?category=books
/products/books
Mit View-Parametern
@Named
@RequestScoped
@Join(path = "/products/{category}",
to = "/faces/products.xhtml")
public class ProductListPage {
// <f:viewParam name=“category“ ...>
private String category;
/* ... */
}
Ohne View-Parameter
@Named
@RequestScoped
@Join(path = "/products/{category}",
to = "/faces/products.xhtml")
public class ProductListPage {
@Parameter
private String category;
/* ... */
}
Validierung
@Named
@RequestScoped
@Join(path = "/products/{category}",
to = "/faces/products.xhtml")
public class ProductListPage {
@Parameter
@Matches("[a-zA-Z-]+")
private String category;
/* ... */
}
JSF Validators
@Named
@RequestScoped
@Join(path = "/products/{category}",
to = "/faces/products.xhtml")
public class ProductListPage {
@Parameter
@Validate(with = CategoryValidator.class)
private String category;
/* ... */
}
Request Actions
Request Actions
@Named
@RequestScoped
@Join(path = "/home",
to = "/faces/home.xhtml")
public class HomePage {
@RequestAction
public void init() {
/* your code */
}
}
Ignore Postbacks
@Named
@ViewScoped
@Join(path = "/home",
to = "/faces/home.xhtml")
public class HomePage {
@RequestAction
@IgnorePostback
public void init() {
/* your code */
}
}
Deferral
@Named
@ViewScoped
@Join(path = "/home",
to = "/faces/home.xhtml")
public class HomePage {
@RequestAction
@Deferred(before = Phase.RENDER_RESPONSE)
public void prepareRender() {
/* your code */
}
}
Navigation
Navigation
<h:link outcome="/products.xhtml">
<f:param name="category" value="books"/>
Bücher
</h:link>
<a href="/products/books">
Bücher
</a>
Navigation
public class SomePage {
public String actionMethod() {
/* do something */
return "/products.xhtml?category=books" +
"&faces-redirect=true";
}
}
Navigation
public class SomePage {
public Navigate actionMethod() {
/* do something */
return Navigate.to(ProductListPage.class)
.with("category", "books");
}
}
Was kann Rewrite noch?
Content Delivery Networks
(CDN)
JSF Resources
<h:outputScript name="jquery.js" />
<script type="text/javascript"
src="/faces/javax.faces.resource/jquery.js" />
<script type="text/javascript"
src="http://dh8sm43.cloudfront.net/jquery.js" />
Erzeugt
Gewünscht
CDN URL Relocation
.addRule(
CDN.relocate("/faces/javax.faces.resource/jquery.js")
.to("http://dh8sm43.cloudfront.net/jquery.js")
)
Resource
Transformation
HTTP Response
Rewrite
Transformation
Pipeline
Usecases
• Minification
– JavaScript, CSS
• Compression
– GZIP, Deflate
• Rendering
– SASS, SCSS, Markdown, Textile, ...
• Custom Processing
JavaScript Minify
.addRule()
.when(
Direction.isInbound().and(Path.matches(
"/faces/javax.faces.resource/{*}.js"))
)
.perform(
Transform.with(Minify.js())
)
Rendering
Beispiel: Sass
$blue: #3bbfce;
$margin: 16px;
.content-navigation {
border-color: $blue;
color:
darken($blue, 9%);
}
.border {
padding: $margin / 2;
margin: $margin / 2;
border-color: $blue;
}
.content-navigation {
border-color: #3bbfce;
color: #2b9eab;
}
.border {
padding: 8px;
margin: 8px;
border-color: #3bbfce;
}
Beispiel: Sass
.addRule()
.when(
Direction.isInbound().and(
Path.matches("/styles/{*}.sass"))
)
.perform(
Response.setContentType("text/css").and(
Transform.with(Sass.compiler()))
);
Wie migriere ich meine
PrettyFaces Anwendung?
Rewrite PrettyFaces Module
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-config-prettyfaces</artifactId>
<version>2.0.0.Final</version>
</dependency>
• Drop-In Replacement für PrettyFaces
• „Sanfte“ Migration
Thank you!
http://ocpsoft.org/rewrite/
Christian Kaltepoth
christian@kaltepoth.de
@chkal

More Related Content

PDF
Beyond PrettyFaces - Einführung in Rewrite
PDF
Web Applications with AngularJS
PDF
Javascript ui for rest services
ODP
A Good PHP Framework For Beginners Like Me!
PDF
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
PDF
Resource Registries: Plone Conference 2014
PDF
Manipulating Magento - Meet Magento Belgium 2017
PDF
.Net template solution architecture
Beyond PrettyFaces - Einführung in Rewrite
Web Applications with AngularJS
Javascript ui for rest services
A Good PHP Framework For Beginners Like Me!
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Resource Registries: Plone Conference 2014
Manipulating Magento - Meet Magento Belgium 2017
.Net template solution architecture

What's hot (20)

PPTX
Mule esb
PPTX
Building and Managing Projects with Maven
PPTX
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
PDF
AngularJS 101 - Everything you need to know to get started
PPTX
Building and managing java projects with maven part-III
PDF
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
PPTX
Single Page WebApp Architecture
PPT
Managing JavaScript Dependencies With RequireJS
PPTX
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
PPTX
MVC Frameworks for building PHP Web Applications
PPTX
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Get...
PDF
Two scoops of django 1.6 - Ch7, Ch8
PDF
Angularjs architecture
PPTX
Building single page applications
PDF
AngularJS Deep Dives (NYC GDG Apr 2013)
PDF
PHP & MVC
PPTX
Put a little Backbone in your WordPress
PDF
Building Web Applications with Zend Framework
PDF
Modern Web Application Development Workflow - EclipseCon Europe 2014
Mule esb
Building and Managing Projects with Maven
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
AngularJS 101 - Everything you need to know to get started
Building and managing java projects with maven part-III
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Single Page WebApp Architecture
Managing JavaScript Dependencies With RequireJS
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
MVC Frameworks for building PHP Web Applications
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Get...
Two scoops of django 1.6 - Ch7, Ch8
Angularjs architecture
Building single page applications
AngularJS Deep Dives (NYC GDG Apr 2013)
PHP & MVC
Put a little Backbone in your WordPress
Building Web Applications with Zend Framework
Modern Web Application Development Workflow - EclipseCon Europe 2014
Ad

Similar to Beyond PrettyFaces - Einführung in Rewrite (20)

ZIP
Web Scraping In Ruby Utosc 2009.Key
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
Spring Surf 101
PPTX
Microdata semantic-extend
PPT
Getting More Traffic From Search Advanced Seo For Developers Presentation
PDF
Intro To Mvc Development In Php
PDF
Great APIs - Future of Your Progress App
PPT
Advanced SEO for Web Developers
PPTX
Code Generation in Magento 2
PDF
AEM Sightly Deep Dive
PDF
Supercharging your Organic CTR
PPT
Diagnosing Technical Issues With Search Engine Optimization
PDF
URL Design
ODP
WordPress Accessibility: WordCamp Chicago
PDF
An Introduction to Tornado
ODP
Pyramid Lighter/Faster/Better web apps
PPT
Introduction to ASP.NET MVC
Web Scraping In Ruby Utosc 2009.Key
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
Spring Surf 101
Microdata semantic-extend
Getting More Traffic From Search Advanced Seo For Developers Presentation
Intro To Mvc Development In Php
Great APIs - Future of Your Progress App
Advanced SEO for Web Developers
Code Generation in Magento 2
AEM Sightly Deep Dive
Supercharging your Organic CTR
Diagnosing Technical Issues With Search Engine Optimization
URL Design
WordPress Accessibility: WordCamp Chicago
An Introduction to Tornado
Pyramid Lighter/Faster/Better web apps
Introduction to ASP.NET MVC
Ad

More from Christian Kaltepoth (6)

PDF
TypeScript - das bessere JavaScript!?
PDF
JavaScript im Jahr 2016
PDF
MVC 1.0 - Das neue Webframework in Java EE 8
PDF
JSF vs. GWT? JSF und GWT!
PDF
Feature Flags mit Togglz
PDF
PrettyFaces: RESTful URLs für JSF
TypeScript - das bessere JavaScript!?
JavaScript im Jahr 2016
MVC 1.0 - Das neue Webframework in Java EE 8
JSF vs. GWT? JSF und GWT!
Feature Flags mit Togglz
PrettyFaces: RESTful URLs für JSF

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Machine Learning_overview_presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Getting Started with Data Integration: FME Form 101
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
1. Introduction to Computer Programming.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Machine Learning_overview_presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Getting Started with Data Integration: FME Form 101
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
1. Introduction to Computer Programming.pptx

Beyond PrettyFaces - Einführung in Rewrite