SlideShare a Scribd company logo
Custom Components
in JSF
UI components in JSF
• javax.faces.component.UIComponent
– Java class that is responsible for representing
a self-contained piece of the user interface
• Renderer
– helper to the UIComponent that deals with
how that specific UIComponent class should
appear in a specific kind of client device.
Why to use a custom renderer
• Separate the semantics of a component
from its appearance
• Support different kinds of client devices
with the same kind of authoring
experience
• Associate your custom component with
different renderers so that you can
render the component on different
clients.
When to use a custom component
• You need to add new behavior to a standard component, such as
generating an additional type of event
• You need to take a different action in the request processing of the
value of a component from what is available in any of the existing
standard components.
• You want to take advantage of an HTML capability offered by your
target browser, but none of the standard JavaServer Faces
components take advantage of the capability in the way you want, if
at all.
• You need to render to a non-HTML client that requires extra
components not supported by HTML.
– you might also need a custom renderer along with the component;
or you might need only a custom renderer.
When not to use a custom
component
• You need to aggregate components to create a new component that has its
own unique behavior
– use a composite component
• You simply need to manipulate data on the component or add application-
specific functionality to it.
– create a managed bean
• You need to convert a component’s data to a type not supported by its
renderer.
– use a converter
• You need to perform validation on the component data.
– use a validator
• You need to register event listeners on components.
– use the f:valueChangeListener and f:actionListener tags
or
– bind the component’s actionListener or valueChangeListener attributes
to a method in a managed bean
Composite components
• A special type of template that acts as a component
• Consists of a collection of markup tags and other
existing components
• Has a customized, defined functionality
• Can have validators, converters, and listeners attached
to it like any other component.
• Most common tags: composite:interface,
composite:implementation,
composite:attribute, composite:valueHolder,
composite:actionSource
Creating a composite component
• Create a .xhtml file, and declare the composite
namespace.
• Use composite tags composite:interface,
composite:attribute and
composite:implementation, to define content of
the composite component.
• Put composite components (“.xhtml” file) into
JSF’s resources folder
• Use the composite component
– The folder name of the composite components is
defined the component access path
Creating a custom tag
• Create a xhtml file and define contents in it
using ui:composition tag
• Create a tag library descriptor (.taglib.xml
file) and declares the above custom tag in
it.
• Register the tag library descriptor in
web.xml
• Use custom tag
Creating a custom validator
• Create a validator class by implements
javax.faces.validator.Validator interface.
• Override validate() method.
• Assign an unique validator ID via
@FacesValidator annotation.
• Reference custom validator class to JSF
component via f:validator tag.
Creating a custom converter
• Create a converter class by implementing
javax.faces.convert.Converter interface.
• Override both getAsObject() and
getAsString() methods.
• Assign an unique converter ID with
@FacesConverter annotation.
• Link your custom converter class to JSF
component via f:converter tag.
Q&A
Sources
• Oracle Docs. The Java EE 6 Tutorial.
http://docs.oracle.com/javaee/6/tutorial/doc/
• WebCenter Content Developer's Guide for Content Server. Chapter
15: Creating Custom Components.
http://docs.oracle.com/cd/E23943_01/doc.1111/e10807/c15_create_
custom_comp.htm#CSSDK1227
• M. Kyong. Custom Tags in JSF 2.0.
http://www.mkyong.com/jsf2/custom-tags-in-jsf-2-0/
• M. Kyong. Custom Converter in JSF 2.0.
http://www.mkyong.com/jsf2/custom-converter-in-jsf-2-0/
• M. Kyong. Custom Validator in JSF 2.0.
http://www.mkyong.com/jsf2/custom-validator-in-jsf-2-0/

More Related Content

Similar to Custom components in JSF

React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
Tech Talk Live on Share Extensibility
Tech Talk Live on Share ExtensibilityTech Talk Live on Share Extensibility
Tech Talk Live on Share Extensibility
Alfresco Software
 
SFDC UI - Advanced Visualforce
SFDC UI - Advanced VisualforceSFDC UI - Advanced Visualforce
SFDC UI - Advanced Visualforce
Sujit Kumar
 
CUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in ShareCUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in Share
Alfresco Software
 
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)
SURBHI SAROHA
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
Hitesh Parmar
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 Recipes
Josh Juneau
 
Aura Framework Overview
Aura Framework OverviewAura Framework Overview
Aura Framework Overview
rajdeep
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
Salesforce Developers
 
Test Automation in Flex - Richa Sharma
Test Automation in Flex - Richa SharmaTest Automation in Flex - Richa Sharma
Test Automation in Flex - Richa Sharma
IndicThreads
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
Ran Wahle
 
Ember.js: Jump Start
Ember.js: Jump Start Ember.js: Jump Start
Ember.js: Jump Start
Viacheslav Bukach
 
Dreamforce 2017 - Up close and personal with Lightning Experience as Platform
Dreamforce 2017 - Up close and personal with Lightning Experience as PlatformDreamforce 2017 - Up close and personal with Lightning Experience as Platform
Dreamforce 2017 - Up close and personal with Lightning Experience as Platform
andyinthecloud
 
Building extensible application using MEF
Building extensible application using MEFBuilding extensible application using MEF
Building extensible application using MEF
Ronak Thakkar
 
CUST-3 Document Management with Share
CUST-3 Document Management with ShareCUST-3 Document Management with Share
CUST-3 Document Management with Share
Alfresco Software
 
Java beans
Java beansJava beans
Java beans
Umair Liaqat
 
My Very First Zf App Part One
My Very First Zf App   Part OneMy Very First Zf App   Part One
My Very First Zf App Part One
isaaczfoster
 

Similar to Custom components in JSF (20)

Unit4wt
Unit4wtUnit4wt
Unit4wt
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Tech Talk Live on Share Extensibility
Tech Talk Live on Share ExtensibilityTech Talk Live on Share Extensibility
Tech Talk Live on Share Extensibility
 
SFDC UI - Advanced Visualforce
SFDC UI - Advanced VisualforceSFDC UI - Advanced Visualforce
SFDC UI - Advanced Visualforce
 
CUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in ShareCUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in Share
 
Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)Java Beans Unit 4(part 2)
Java Beans Unit 4(part 2)
 
Introduction to java beans
Introduction to java beansIntroduction to java beans
Introduction to java beans
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 Recipes
 
Aura Framework Overview
Aura Framework OverviewAura Framework Overview
Aura Framework Overview
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
 
Test Automation in Flex - Richa Sharma
Test Automation in Flex - Richa SharmaTest Automation in Flex - Richa Sharma
Test Automation in Flex - Richa Sharma
 
Angular js 2
Angular js 2Angular js 2
Angular js 2
 
Ember.js: Jump Start
Ember.js: Jump Start Ember.js: Jump Start
Ember.js: Jump Start
 
Dreamforce 2017 - Up close and personal with Lightning Experience as Platform
Dreamforce 2017 - Up close and personal with Lightning Experience as PlatformDreamforce 2017 - Up close and personal with Lightning Experience as Platform
Dreamforce 2017 - Up close and personal with Lightning Experience as Platform
 
Building extensible application using MEF
Building extensible application using MEFBuilding extensible application using MEF
Building extensible application using MEF
 
CUST-3 Document Management with Share
CUST-3 Document Management with ShareCUST-3 Document Management with Share
CUST-3 Document Management with Share
 
Java beans
Java beansJava beans
Java beans
 
My Very First Zf App Part One
My Very First Zf App   Part OneMy Very First Zf App   Part One
My Very First Zf App Part One
 
Struts2
Struts2Struts2
Struts2
 

More from ESRI Bulgaria

Dreamix
Dreamix Dreamix
Dreamix
ESRI Bulgaria
 
The Art of Communication In IT Projects
The Art of Communication In IT ProjectsThe Art of Communication In IT Projects
The Art of Communication In IT Projects
ESRI Bulgaria
 
Oracle Business Intelligence Enterprise Edition
Oracle Business Intelligence Enterprise EditionOracle Business Intelligence Enterprise Edition
Oracle Business Intelligence Enterprise Edition
ESRI Bulgaria
 
Arduino Basics
Arduino BasicsArduino Basics
Arduino Basics
ESRI Bulgaria
 
What you Need to Know about Machine Learning?
What you Need to Know about Machine Learning?What you Need to Know about Machine Learning?
What you Need to Know about Machine Learning?
ESRI Bulgaria
 
From Developer to Consultant
From Developer to ConsultantFrom Developer to Consultant
From Developer to Consultant
ESRI Bulgaria
 
CrashCourse: XML technologies
CrashCourse: XML technologiesCrashCourse: XML technologies
CrashCourse: XML technologies
ESRI Bulgaria
 
Architecture review vs Post Implementation Review
Architecture review vs Post Implementation ReviewArchitecture review vs Post Implementation Review
Architecture review vs Post Implementation ReviewESRI Bulgaria
 
How to Deliver a Successful Oracle BPM and SOA Suite Project
How to Deliver a Successful Oracle BPM and SOA Suite ProjectHow to Deliver a Successful Oracle BPM and SOA Suite Project
How to Deliver a Successful Oracle BPM and SOA Suite Project
ESRI Bulgaria
 
How blogs are affecting your company
How blogs are affecting your company How blogs are affecting your company
How blogs are affecting your company
ESRI Bulgaria
 
Tips and tricks for the best user-friendly website
Tips and tricks for the best user-friendly website Tips and tricks for the best user-friendly website
Tips and tricks for the best user-friendly website
ESRI Bulgaria
 
Solution for your employees satisfaction - A$4
Solution for your employees satisfaction - A$4 Solution for your employees satisfaction - A$4
Solution for your employees satisfaction - A$4
ESRI Bulgaria
 

More from ESRI Bulgaria (14)

Dreamix
Dreamix Dreamix
Dreamix
 
The Art of Communication In IT Projects
The Art of Communication In IT ProjectsThe Art of Communication In IT Projects
The Art of Communication In IT Projects
 
Oracle Business Intelligence Enterprise Edition
Oracle Business Intelligence Enterprise EditionOracle Business Intelligence Enterprise Edition
Oracle Business Intelligence Enterprise Edition
 
Arduino Basics
Arduino BasicsArduino Basics
Arduino Basics
 
Single sign-on
Single sign-onSingle sign-on
Single sign-on
 
What you Need to Know about Machine Learning?
What you Need to Know about Machine Learning?What you Need to Know about Machine Learning?
What you Need to Know about Machine Learning?
 
SVN Best Practices
SVN Best PracticesSVN Best Practices
SVN Best Practices
 
From Developer to Consultant
From Developer to ConsultantFrom Developer to Consultant
From Developer to Consultant
 
CrashCourse: XML technologies
CrashCourse: XML technologiesCrashCourse: XML technologies
CrashCourse: XML technologies
 
Architecture review vs Post Implementation Review
Architecture review vs Post Implementation ReviewArchitecture review vs Post Implementation Review
Architecture review vs Post Implementation Review
 
How to Deliver a Successful Oracle BPM and SOA Suite Project
How to Deliver a Successful Oracle BPM and SOA Suite ProjectHow to Deliver a Successful Oracle BPM and SOA Suite Project
How to Deliver a Successful Oracle BPM and SOA Suite Project
 
How blogs are affecting your company
How blogs are affecting your company How blogs are affecting your company
How blogs are affecting your company
 
Tips and tricks for the best user-friendly website
Tips and tricks for the best user-friendly website Tips and tricks for the best user-friendly website
Tips and tricks for the best user-friendly website
 
Solution for your employees satisfaction - A$4
Solution for your employees satisfaction - A$4 Solution for your employees satisfaction - A$4
Solution for your employees satisfaction - A$4
 

Recently uploaded

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 

Recently uploaded (20)

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 

Custom components in JSF

  • 2. UI components in JSF • javax.faces.component.UIComponent – Java class that is responsible for representing a self-contained piece of the user interface • Renderer – helper to the UIComponent that deals with how that specific UIComponent class should appear in a specific kind of client device.
  • 3. Why to use a custom renderer • Separate the semantics of a component from its appearance • Support different kinds of client devices with the same kind of authoring experience • Associate your custom component with different renderers so that you can render the component on different clients.
  • 4. When to use a custom component • You need to add new behavior to a standard component, such as generating an additional type of event • You need to take a different action in the request processing of the value of a component from what is available in any of the existing standard components. • You want to take advantage of an HTML capability offered by your target browser, but none of the standard JavaServer Faces components take advantage of the capability in the way you want, if at all. • You need to render to a non-HTML client that requires extra components not supported by HTML. – you might also need a custom renderer along with the component; or you might need only a custom renderer.
  • 5. When not to use a custom component • You need to aggregate components to create a new component that has its own unique behavior – use a composite component • You simply need to manipulate data on the component or add application- specific functionality to it. – create a managed bean • You need to convert a component’s data to a type not supported by its renderer. – use a converter • You need to perform validation on the component data. – use a validator • You need to register event listeners on components. – use the f:valueChangeListener and f:actionListener tags or – bind the component’s actionListener or valueChangeListener attributes to a method in a managed bean
  • 6. Composite components • A special type of template that acts as a component • Consists of a collection of markup tags and other existing components • Has a customized, defined functionality • Can have validators, converters, and listeners attached to it like any other component. • Most common tags: composite:interface, composite:implementation, composite:attribute, composite:valueHolder, composite:actionSource
  • 7. Creating a composite component • Create a .xhtml file, and declare the composite namespace. • Use composite tags composite:interface, composite:attribute and composite:implementation, to define content of the composite component. • Put composite components (“.xhtml” file) into JSF’s resources folder • Use the composite component – The folder name of the composite components is defined the component access path
  • 8. Creating a custom tag • Create a xhtml file and define contents in it using ui:composition tag • Create a tag library descriptor (.taglib.xml file) and declares the above custom tag in it. • Register the tag library descriptor in web.xml • Use custom tag
  • 9. Creating a custom validator • Create a validator class by implements javax.faces.validator.Validator interface. • Override validate() method. • Assign an unique validator ID via @FacesValidator annotation. • Reference custom validator class to JSF component via f:validator tag.
  • 10. Creating a custom converter • Create a converter class by implementing javax.faces.convert.Converter interface. • Override both getAsObject() and getAsString() methods. • Assign an unique converter ID with @FacesConverter annotation. • Link your custom converter class to JSF component via f:converter tag.
  • 11. Q&A
  • 12. Sources • Oracle Docs. The Java EE 6 Tutorial. http://docs.oracle.com/javaee/6/tutorial/doc/ • WebCenter Content Developer's Guide for Content Server. Chapter 15: Creating Custom Components. http://docs.oracle.com/cd/E23943_01/doc.1111/e10807/c15_create_ custom_comp.htm#CSSDK1227 • M. Kyong. Custom Tags in JSF 2.0. http://www.mkyong.com/jsf2/custom-tags-in-jsf-2-0/ • M. Kyong. Custom Converter in JSF 2.0. http://www.mkyong.com/jsf2/custom-converter-in-jsf-2-0/ • M. Kyong. Custom Validator in JSF 2.0. http://www.mkyong.com/jsf2/custom-validator-in-jsf-2-0/