Jsf presentation

  • 1,572 views
Uploaded on

Discusses in brief about JSF, Component And Request Based Frameworks and a touch on Market Trends

Discusses in brief about JSF, Component And Request Based Frameworks and a touch on Market Trends

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,572
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
29
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Java Server Faces (JSF)Brief Introduction and Market Trends Created by :Ashish Gupta
  • 2. Instruction Guide ContentsMVC 3Request Based & Component Based Frameworks 4Introduction to JSF 5Lifecycle of JSF 7JSF Components 9Introduction to Facelets 15Difference between JSF and JSF 2 16Comparison of Top 3 MVC 17Google Trends 18Market Trends 19
  • 3. What is MVC ?The model-view-controller (MVC) architecture provides a set of design patterns thathelp you separate the areas of concern involved in building and running a GUI or Webbased application:MODEL encapsulates the business logic and persistence code for the application. It should be as view-technology-agnostic as possible. For example, the same model should be usable with a Swing application, a Struts app, or a JSF app.VIEW should display model objects and contain presentation logic only. There should be no business logic or controller logic in the view.CONTROLLER acts as the mediator between the view and the model. The controller talks to the model and delivers model objects to the view to display. In an MVC architecture the controller always selects the next view..
  • 4. Diff. between Request and Component Based FrameworksRequest based framework is basically a web framework that gets users request then determine whatthe system should do and give back the response back to the user. Example are Struts 2, Grails Flow is linear Intimately tied to the HTTP request cycle and request format.Provide only basic API extensions and services – like simple page navigation, data entry validation and mapping.Explicit coding by developer for every requestAction Framework is work better in stateless environments Scenario  If youre going to do a "web site", where URLs are important, lots of read only, higherloads of simpler traffic, etc.Component based framework We think in component and define components and tell what it does.They attempt to abstract this away and treat the application as collections of components with renderersand actions to do things. Examples are JSF, WicketHas no clear sense of the flow from front to back thus non-linearIt tends to hide the underlying HTTP request and use its own, higher level abstraction.Typically have a lot of session state associated with them.They operate on the higher level of abstraction and allow you to build user interface from ready-made UI components.Favorable for people who don’t have much experience in advanced HTML, CSS ,vanilla JS and JS libraries,Scenario  If its a back office application, lots of CRUD screens, not as many users, complicated pageand workflows, lots of page component interaction
  • 5. Introduction to JSFJavaServer Faces (JSF) is the well-established standard for web-developmentframeworks in Java.A component based MVC framework which is built on top of Servlet APIProviding components in the type of taglibs which can be used in JSP or Facelets.(Both are view technologies)A typical JSF application consists of the following parts:Event-driven development (via listeners as in traditional GUI development).Pages that represent MVC-style views and set of tags to add components to the webpages.A set of managed beans (POJOs) They support services, such as resource injection,lifecycle callbacks and interceptors.Optionally, one or more application configuration resource files, such as a faces-config.xml file, which can be used to define page navigation rules and configure beansand other custom objects, such as custom components.A set of custom objects, which can include custom components, validators, converters,or listeners, created by developers.
  • 6. Introduction to JSF (cont.)FacesServlet is the sole request-response Controller.It takes all the standard and tedious HTTP request/response work such as  Gathering user input and Validating/converting them Putting inputs in model objects Invoking actions and rendering the response.JSF provides the following development advantages:Clean separation of behavior and presentation.Component-level control over statefulnessEvents easily tied to server-side codeLeverages familiar UI-component and Web-tier conceptsOffers multiple, standardized vendor implementationsJSFs fine-tuned event model allows your applications to be less tied to HTTP detailsand simplifies your development effort.Reuse and extend components through customization.
  • 7. Lifecycle of JSF
  • 8. Lifecycle of JSF (contd.)Restore component tree The controller examines the request and extracts the view ID, determined by the name of the JSPIf the view doesnt already exist, the JSF controller creates it otherwise creates it.The view contains all the GUI components.Apply Request ValuesThe purpose of this phase is for each component to retrieve its current state.Component values are typically retrieved from the request parameters.Process ValidationsAt this stage, each component will have its values validated against the applications validation rules.Update ModelUpdates the actual values of the server-side model --namely, by updating the properties of your backing beans.Invoke ApplicationThe JSF controller invokes the application to handle Form submissions.The component values will have been converted, validated, and applied to the model objects, so you can now use them to execute the applications business logic.Render ResponseYou display the view with all of its components in their current state. Basically, render page & send it back to client
  • 9. JSF ComponentsJSF UI Components  UI Input UI Output UI SelectBooleanUI SelectMany UI SelectOne UI SelectMany UI Graphic UICommand UI FormJSF HTML Tag Library JSF Core Tag Library ( Validator, Event Listeners and Converters)JSF Standard Library (Express UI Components)JSF Managed Beans Use to separate presentation from business logicBased on JavaBeans and use the declarative modelEntry point into the model and event handlersJSF Value Binding  Bind component value andattribute to model objectsLiteral: <h:outputText rendered=”true”value=”$1000.00”/>Value Binding:<h:outputText rendered=”#{user.manager}”value=”#{employee.salary}”/>
  • 10. JSF Value binding expression can acceptBean propertiesListArrayMapPredefine objects-header, header values, request parameters, cookie,request/session/application scope attributes, initial parametersJSF Method Binding --> Binding an event handler to a method <h:commandButton action=“#{user.login}”/>Four component attributes:ActionAction listenerValue change listenerValidatorJSF Events are fired by each UI component. Event handlers are registered with eachcomponent
  • 11. Value Changed Listener: <h:inputTextid=”maxUsers”valueChangeListener=“#{user.checkMaxUser}”/> public void checkMaxUser(ValueChangeEventevt) { evt.getNewValue(); // new value evt.getOldValue(); // old value }Action Listener: <h:commandButtonvalue="Login“actionListener=“#{customer.loginActionLis tener}” action=“#{customer.login}”/> public void loginActionListener(ActionEvente) { } public String login() { return “OK”; }Listener Handlers a) Implement UI logic b) Have access to event source c) Do not participate innavigation handlingAction Handlers a) Implement business logic b) Don’t have access to action source c) Returnedoutcome affects the navigation handling.JSF ValidatorsFor validating user input0 or more validators can be registered with a UI Input componentValidators are invoked during the Process Validation srequest processing phase.Standard validators and custom validator are present.
  • 12. Required Validation Example <h:inputTextvalue=“#{user.id}”required=“true”/>Length Validation Example <h:inputTextvalue=“#{user.password}”> <f:validateLengthminimum=“6”/> <f:validatorvalidatorId=“passwordValidator”/> </h:inputText>JSF Converters Type conversion between server-side objects and their representation inmarkup language. e.g. DateTime and Number.Number converter example: <h:inputTextvalue=“#{rent.amt}”converter=“Number”> <f:attributename=“numberStyle”value=“currency”/> </h:inputText>Date convert example: <h:inputTextvalue=“#{rent.dueDate}”converter=“DateFormat”> <f:attributename=“formatPattern”value=“MM/DD”/> </h:inputText>JSF Error Handling contains summary and detail (Information, Warning, Error, Fatal)<h:messages> - to display all messages<h:message> - to display a single message for a particular componentJSF HTML & CSS Integration Pass-through attributes <h:inputTextsize=“5”onblur=“checkValue();”/>StylesheetsIntegration <h:outputTextstyleClass=“header”value=“#{bundle.welcome}”/>
  • 13. JSF Navigation A default navigational handler . Behavior is configured in configuration file (faces- config.xml). <navigation-rule> <description>LOGIN PAGE NAVIGATION HANDLING</description> <from-view-id> /login.jsp</from-view-id> <navigation-case> <description>Handle case where login succeeded.</description> <display-name>Successful Login</display-name> <from-action>#{userBean.login}</from-action> <from-outcome>success</from-outcome> <to-view-id>/home.jsp</to-view-id> </navigation-case> <navigation-case> <description>Registration fornew user succeeded.</description> <display-name>Successful New User Registration</display-name> <from-action>#{userBean.register}</from-action> <from-outcome>success</from-outcome> <to-view-id>/welcome.jsp</to-view-id> </navigation-case> </navigation-rule>
  • 14. JSF HTML Tag Library <f:view> <h:form id=”logonForm”> <h:panelGrid columns=”2”> <h:outputLabel for=”username”> <h:outputLext value=”Username:”/> </h:outputLabel> <h:inputText id=”username” value=”#{logonBean.username}”/> <h:outputLabel for=”password”> <h:outputText value=”Password:”/> </h:outputLabel> <h:inputSecret id=”password” value=”#{logonBean.password}”/> <h:commandButton id=”submitButton”type=”SUBMIT” action=”#{logonBean.logon}”/> <h:commandButton id=”resetButton” type=”RESET”/> </h:panelGrid> </h:form> </f:view>
  • 15. Introduction to Facelets Facelets is an open source XML-based view technology designed specifically for JSF Advantages Provides great templating capabilities such as composite components whereas JSP provides include directive only.  Default view handler technology for JSF 2.  Faster compilation time and High-performance rendering then JSP  Compile-time EL validation  Support for code reuse through templating and composite components. Tag Library Prefix Example URI ContentsJavaServer Faces Facelets ui:component ui: http://java.sun.com/jsf/facelet Tags for templatingTag Library ui:insert s h:headJavaServer Faces HTML Tag h:body JavaServer Faces component tags for all h: http://java.sun.com/jsf/htmlLibrary h:outputText UIComponentobjects h:inputText Tags for JavaServer Faces customJavaServer Faces Core Tag f:actionListener f: http://java.sun.com/jsf/core actions that are independent of anyLibrary f:attribute particular render kit
  • 16. Difference between JSF2 and JSFJSP is replaced by Facelets as the default view technology.Facelets was expanded with capabilities to create custom components using pure XML(the so-called composite components).Ajaxical powers were introduced in flavor of the <f:ajax> component and like whichhas much similarities with Ajax4jsf. With JSF 2.0, more nice-looking componentlibraries were born, among others PrimeFaces andOpenFaces.Annotations and convention-over-configuration enhancements were introduced to killthe verbose faces-config.xml file as much as possible.The ID separator character : became configurable.A new scope was introduced, the view scope. This scope will live as long as youresubsequently submitting and navigating to the same view (independently of the openedbrowser tab/window), either synchronously or asynchronously.Difference between JSF Implementations and JSF ComponentsJSF implementations implements the JSF API Specification. They contains at leastthe standard components to display any of the available basic HTML elements. There aretwo (major) JSF implementations, namely Oracle Mojarra and Apache MyFaces.JSF component libraries adds extra on top of the basic implementation, often withmore skinnability, ajaxability, enhanceability, etc. There are lot of them likePrimeFaces, RichFaces, IceFaces.
  • 17. Comparison on Top 3 Industry MVC (1 being good and 3 being bad) Criteria/Framework JSF STRUTS 2 SPRING MVC LEARNING CURVE 3 1 2 PROJECT HEALTH 2 3 1 DOCUMENTATION 1 3 1 JOB TRENDS 1 1 1 AJAX SUPPORT ICE FACES / IN-BUILT DOJO/JQUERY PLUGIN 3RD PARTY BOOKMARKING AND URL POST (NOT POSSIBLE) USES NAMESPACES (EASY) FULL URL CONTROL OGNL EXPRESSION BUT NEED VALIDATION EASY TO CONFIGURE COMMONS VALIDATOR CONF FOR CLIENT SIDE ALLOWS TO ADD PARAMS TO POST & REDIRECT REQUIRES CUSTOM SOLN REQUIRES CUSTOM SOLN REDIRECT DEMAND MEDIUM LOWEST HIGHEST PLUGINS HIGHEST MEDIUM LOWEST DEVELOPERS AVAILABLE MEDIUM LOWEST HIGHEST REST SUPPORT LOWEST MEDIUM HIGHESTTAGGED QUESTION/SUPPORT MEDIUM LOWEST HIGHEST
  • 18. Google TrendsLast 12 months with Spring MVC
  • 19. Market Trends
  • 20. THANKS !!!!!!