Java Server Faces aatay ivici Apache My Faces

  • Slides: 28
Download presentation
Java Server Faces Çağatay Çivici Apache My. Faces Team Member cagatay@apache. org

Java Server Faces Çağatay Çivici Apache My. Faces Team Member cagatay@apache. org

Çağatay Çivici o o o o Apache My. Faces Project Committer Open. Logic Expert

Çağatay Çivici o o o o Apache My. Faces Project Committer Open. Logic Expert Group Member Sourceforge jsf-comp project developer JSF Client Side Validators Acegi Security Framework’s JSF Components JFree. Chart for JSF : JSF Chart Creator Faces. Trace: Visual Debugger of JSF

Agenda o o o o What is JSF? JSF Component Model and Binding mechanism

Agenda o o o o What is JSF? JSF Component Model and Binding mechanism JSF Request Lifecycle IOC and Managed Beans Navigations Internalization and Resource Bundles Extending JSF Integration with Other Frameworks (Spring Framework Example) Ajax with JSF Facelets Apache My. Faces IDE Support Future of JSF Questions

What is JSF? o o o a component oriented and event driven web framework

What is JSF? o o o a component oriented and event driven web framework to build up web applications. a Standard various implementations n n Sun Reference Implementation Apache My. Faces Oracle ADF IBM

Architecture

Architecture

Similar Concepts o o Asp. net Tapestry Wicket Swing

Similar Concepts o o Asp. net Tapestry Wicket Swing

JSF vs Struts o Struts is an action framework n o Controller of the

JSF vs Struts o Struts is an action framework n o Controller of the MVC pattern JSF is an event driven and component oriented framework. n JSF contains all the members of the MVC. o o o Model : Managed Beans View : Components Controller : Faces Servlet

JSF Component Model o Covers a wide range components. n n n o o

JSF Component Model o Covers a wide range components. n n n o o o Reusable Customizable State aware Easy to plug in third party components. Easy to create custom components of your own. Renderers brings abstraction

Simple Example: Html. Input. Text o Declared as; n o Gives the output n

Simple Example: Html. Input. Text o Declared as; n o Gives the output n o <h: input. Text id=“id 1” value=“xxx” /> <input type=“text” id=“parentformid: id 1” value=“xxx” /> Customization attributes like; n n Styleclass Javascript events (onmousover etc. . . )

Binding makes JSF powerful o Value binding; binds a bean’s variable to a component.

Binding makes JSF powerful o Value binding; binds a bean’s variable to a component. n o <h: input. Text value=“#{person. name}” /> Action binding, binds a method to an action component. n <h: command. Button action=“{person. Save. Page. save. Person}” />

JSF Component Tree o o Components are represented using a tree. <f: view> <h:

JSF Component Tree o o Components are represented using a tree. <f: view> <h: form id=“form 1”> <h: output. Text id=“lbl_name” value=“Name”> <h: input. Text id=“txt_name” value=“Name. Value”> </h: form> </f: view>

Event Handling o o Events are created based on the request parameters. Each event

Event Handling o o Events are created based on the request parameters. Each event is broadcasted to the related listeners.

State Management o JSF saves and restores the state of the components in each

State Management o JSF saves and restores the state of the components in each faces request. n Client o n As a hidden variable Server o As a session entry

JSF Request Life. Cycle

JSF Request Life. Cycle

Conversion and Validation o o o Submitted form values are strings Conversion takes place

Conversion and Validation o o o Submitted form values are strings Conversion takes place to convert these values to java objects Validation mechanism validates these converted objects n n Built-in converters and validators Easy to write custom converters and validators

Case Study

Case Study

IOC and Managed Beans o o JSF uses it’s own container to manage the

IOC and Managed Beans o o JSF uses it’s own container to manage the beans in it’s context. <managed-bean> <managed-bean-name>pc_Index</managed-bean-name> <managed-bean-class>demo. Index</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>some. Variable</property-name> <value>#{pc_DB}</value> </managed-property> </managed-bean> <managed-bean-name>pc_DB</managed-bean-name> <managed-bean-class>demo. Db</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean>

Navigations o <navigation-rule> <from-view-id>/login. jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/mainmenu. jsp</to-view-id> </navigation-case> <from-outcome>failure</from-outcome> <to-view-id>/login. jsp</to-view-id> </navigation-case>

Navigations o <navigation-rule> <from-view-id>/login. jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/mainmenu. jsp</to-view-id> </navigation-case> <from-outcome>failure</from-outcome> <to-view-id>/login. jsp</to-view-id> </navigation-case> </navigation-rule> o Action specific o <from-action>#{login. Bean. login. Action}</from-action> Supports patterns n <from-view-id>*</from-view-id> n

Extending JSF o o o Navigation Handler View Handler Custom Resolvers Phaselisteners Custom Components

Extending JSF o o o Navigation Handler View Handler Custom Resolvers Phaselisteners Custom Components

Multilanguage o Support for resource bundles n <application> <locale-config> <default-locale>tr</default-locale> <supported-locale>en</supported-locale> <supported-locale>en_US</supported-locale> <supported-locale>de</supported-locale> </locale-config>

Multilanguage o Support for resource bundles n <application> <locale-config> <default-locale>tr</default-locale> <supported-locale>en</supported-locale> <supported-locale>en_US</supported-locale> <supported-locale>de</supported-locale> </locale-config> <message-bundle> jsfsunum. messages </message-bundle> </application> o jsfsunum/messages. tr n o msg_welcome = Merhaba Bundles on faces pages n <f: load. Bundle basename=“jsfsunum. labels" var="msg"/>

Integration with Spring o JSF-Spring n o Using a delegating variable resolver <application> <variable-resolver>

Integration with Spring o JSF-Spring n o Using a delegating variable resolver <application> <variable-resolver> org. springframework. web. jsf. Delegating. Variable. Resolver </variable-resolver>; </application> <managed-bean-name>backing. Bean. Name</managed-bean-name> <managed-bean-class> yourpackagename. backing. Bean. Class </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>facade. Service</property-name> <property-class> packagename. Facade. Service </property-class> <value>#{facade. Service}</value> </managed-property> </managed-bean>

Ajax with JSF o o Components with ajax support JSF ajax frameworks n n

Ajax with JSF o o Components with ajax support JSF ajax frameworks n n n JSF Avatar Ajax Anywhere Ajax 4 jsf Ice. Faces Ajax enabled my. Faces components

Facelets o o o Replacing jsp markup with xhtml Templating Composite components Powerful view

Facelets o o o Replacing jsp markup with xhtml Templating Composite components Powerful view handler than jsf 1. 1 No need for tag handlers of jsp

JSF IDE Support o o o o Exadel Studio IBM RSA Oracle JDeveloper Sun

JSF IDE Support o o o o Exadel Studio IBM RSA Oracle JDeveloper Sun Studio Creator My. Eclipse Bea Workshop Macromedia jsftoolbox Netbeans

Introducing Apache My. Faces o o o Open source implementation of JSF Contains extended

Introducing Apache My. Faces o o o Open source implementation of JSF Contains extended tomahawk library Oracle ADF donation

My. Faces Component Demo o o o Basic form components Datatable File upload Date

My. Faces Component Demo o o o Basic form components Datatable File upload Date and Calendar Jscookmenu Schedule Accordion panel Tabbed Panel Ajax components Tree Dojo Toolkit Fisheye Html Editor Chart Creator (jsf-component)

Future o o JSF 1. 2 and later JSF 2. 0 More powerful IDE

Future o o JSF 1. 2 and later JSF 2. 0 More powerful IDE support More components Integrated Ajax Support

The End - Questions? o o cagatay. civici@gmail. com www. jroller. com/page/cagataycivici

The End - Questions? o o cagatay. civici@gmail. com www. jroller. com/page/cagataycivici