1 / 16

Web applications using JavaServer Faces (JSF)

Web applications using JavaServer Faces (JSF). A brief introduction. What is JavaServer Faces (JSF)?. Framework for web applications Works on the server side Part of Java Enterprise Edition Runs on an application server with a JSF container Example: GlassFish. Some web technologies.

tessa
Download Presentation

Web applications using JavaServer Faces (JSF)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web applications using JavaServer Faces (JSF) A brief introduction JavaServer Faces (JSF)

  2. What is JavaServer Faces (JSF)? • Framework for web applications • Works on the server side • Part of Java Enterprise Edition • Runs on an application server with a JSF container • Example: GlassFish JavaServer Faces (JSF)

  3. Some web technologies Client-side technologies Server-side technologies Java Servlets JavaServer Pages (JSP) JavaServer Faces (JSF) PHP Microsoft ASP.NET web forms • (X)HTML • JavaScript • Cascading Styles Sheets (CSS) • Java Applets JavaServer Faces (JSF)

  4. JSF Pages • JSF Pages look like HTML pages • Application server translates JSF Pages to HTML pages • The HTML is then send to the client (browser) • The translation is dynamic • Depends on the state of Java objects • JSF Managed Beans • Syntax: #{beanName.propertyName} JavaServer Faces (JSF)

  5. NetBeans support JavaServer Faces (JSF)

  6. JSF managed beans • Value expression • #{beanName.propertyName} • Invokes a method on a Java object • Called a JSF managed bean • JavaBeans controlled by JSF • Example: showTime JavaServer Faces (JSF)

  7. JavaBeans • No-arguments constructor • Properties • Get + set methods • Public type getPropertyName() • Public void setPropertyName(Type newValue) • Can be read-only • No set method, only a get method • Other methods • Implements java.io.Serializable • The model component in the Model-View-Controller architecture (MVC) • Example: showTime-> TimeBeans JavaServer Faces (JSF)

  8. Scope of managed beansWho can access a bean – and for how long? • @RequestScoped • Available throughout a single HTTP request. • Survives forwarding to another page • @SessionScoped • Stored in the HTTP session • Each user has a HTTP session • Time out • Example: Shopping cart • Examples from “Big Java” uses only @SessionScoped • @ApplicationScoped • Available throughout the life of the application • Accessible to all users and all pages • Example: counters2 JavaServer Faces (JSF)

  9. Separation of concerns:Presentation and Business Logic • Presentation • User interface • JSF Page • Also known as Facelet • Made by graphics designers • Business logic • Rules for business decisions • JSF managed JavaBean • Made by Java programmers JavaServer Faces (JSF)

  10. Navigation between pages • Command button • <h:commandButton value=”text” action=”pageName”> • Example: personalInfo • Action can be a static name, or a method expression • Action=”#{bean.method}” • The method produces a String depending on the bean object’s state • The name of the page to navigate to • <h:commandLink …> • Similar JavaServer Faces (JSF)

  11. JSF components • JSF components are translated into HTML elements using value expressions • Example • <h:inputText value=”#{beanObject.propertyName}” /> • Examples: • personalInfo JavaServer Faces (JSF)

  12. Validators:Checking the users input • Required field • The input field cannot be left empty • <h:inputText value=”…” required=”true” /> • Minimum length of a text input <h:inputText value="#{student.name}" required="true"> <f:validateLength minimum="2" /> </h:inputText> • Range of an number input <h:inputText value="#{student.age}" required="true" > <f:validateLongRange minimum="0" maximum="120" /> </h:inputText> • You can make your own validators • To validate the structure of an email address, etc. JavaServer Faces (JSF)

  13. Three-tier applications • Presentation tier • Browser • Business logic tier • JSF Container • JSF pages + managed beans • Managed beans can make connections to a database • Storage tier • Database Management System (DBMS) • Database JavaServer Faces (JSF)

  14. JSF using MVCBut where is the controller? • Model • JSF managed beans • View • JSF page • Controller • Javax.faces.webapp.FacesServlet • http://download.oracle.com/javaee/6/api/javax/faces/webapp/FacesServlet.html • Reads WEB-INF/web.xml from the project • Dispatches the request to the right JSF page JavaServer Faces (JSF)

  15. Declarative programming • A program that describes what computation should be performed and not how to compute it. • http://en.wikipedia.org/wiki/Declarative_programming • Examples: • SQL, executed by a DBMS • HTML + CSS, executed by a web browser • @Named(value = "user") + @SessionScoped • Executed by a JSF container (application server) JavaServer Faces (JSF)

  16. References and further readings • Horstmann: Big Java 4th edition, Wiley 2010 • Chapter 23 Web Applications, page 925-955 • The Java EE 6 Tutorial, Part III The Web Tier • http://docs.oracle.com/javaee/7/tutorial/doc/partwebtier.htm • Geary & Horstmann: Core JavaServer Faces, 3rd edition, Prentice Hall 2010 • Burns & Schalk: JavaServer Faces 2.0: The Complete Reference, McGraw-Hill 2011 • Hall: JSF 2.0 Tutorials, ${coreservlets.com} • http://www.coreservlets.com/JSF-Tutorial/jsf2/ • JSF 2.0 Support in NetBeans IDE • http://netbeans.org/kb/docs/web/jsf20-support.html#jsfPages JavaServer Faces (JSF)

More Related