Introducing Java Server Faces (JSF) To 4GL Developers

2y ago
27 Views
2 Downloads
720.64 KB
21 Pages
Last View : 8d ago
Last Download : 3m ago
Upload by : Mya Leung
Transcription

Introducing Java Server Faces(JSF) to 4GL DevelopersAn Oracle White PaperNovember 2006

Introducing Java Server Faces (JSF) to 4GLDevelopersIntroduction . 4Introducing JSF . 4A Brief History Lesson . 4Before JSF . 5JSF In the Community . 5Oracle’s contribution . 6Contribution from others. 6Understanding JSF . 6Introducing the component . 6The component architecture . 7Supporting the component. 8A simple component example. 8The event model . 10Action events . 10Value change events. 10Phase events. 11The page flow. 12Introducing faces-config.xml. 12The action attribute. 13The managed bean. 13Managed bean definition. 14Referencing the managed bean . 15Converters and validators. 15Converters . 16Validators. 16The JSF lifecycle . 16Overview. 16Looking at the phases. 17Restore View. 17Apply Request Values. 17Process Validations . 17JSF Advance Features. 18Skinning. 18Render Kits. 19Introducing Java Server Faces (JSF) to 4GL DevelopersPage 2

Ajax . 19Conclusion. 20Introducing Java Server Faces (JSF) to 4GL DevelopersPage 3

Introducing Java Server Faces (JSF) to 4GLDevelopersINTRODUCTIONIBM, BEA, Sun and others have alsocommitted to using JSF as their UItechnology.The past couple of years have seen the emergence of JSF (Java Server Faces) as thetechnology of choice for building the user interface (UI) layer of Java webapplications. Oracle’s own business applications are committing to JSF as the UItechnology in the “Fusion” stack.The component based architecture gives business developers simple, yet powerful,UI components with which to build applications; while being based on standardsmeans that the larger development community can collaborate to build richer andmore advanced components.This paper will introduce JSF to 4GL developers, showing how the componentscan be used, and behind the scenes, how the components work.INTRODUCING JSFThe Java Community Process (JCP), which is responsible for defining the standardfor JSF – initially released as JSR-127 (Java Specification Request 127)- states oneof its goals is to: “ establish a standard API for creating Java Web application GUIs,which will eliminate the burden of creating and maintaining GUI infrastructure for developers.”Which means that JSF is about components in the traditional UI sense of widgetslike buttons, text fields and check boxes. It is not slaved to the traditional mark-upcentric view of previous web technologies: a button is a button, not a tag. It hasbehavior, you can listen for it being pressed and the infrastructure to support whathappens when it is pressed is taken care for you. Which is exactly what you havebeen used to in the Oracle Forms, Visual Basic and PeopleTools world.A Brief History LessonFrom its formative years in 2001, the first release in 2003, up to the current release(JSF 1.2 JSR-252) in 2006 the JCP has brought together resources from thecommunity, including Oracle, to define the specification and produce a referenceimplementation of the specification.Introducing Java Server Faces (JSF) to 4GL DevelopersPage 4

Before JSFIt is difficult to see how far JSF has raised the bar for Java web application UIswithout first being aware of the development experience (or lack of) that was thecatalyst for the simpler UI component based view that JSF typifies.Static HTMLIn the formative years of the web, static HTML (Hyper Text Markup Language)pages made up the bulk of any content you would see on the web. The overridinglimitation was that as static pages it became difficult to display any sort of dynamicdata like a list of products held in a database. Furthermore, if you wanted to domore than simply serve up a series of static pages, you also had to code your owncommunication to and from the server using the HTTP Post and Get messages asthe carrier.ServletsStrictly speaking servlets do not have togenerate HTML; they can generate anymarkup language dependant on the enduser device: e.g. a mobile phone or PDA.To overcome the limitations of static pages, servlets were introduced. Simply aJava program that would do some processing and output a string of HTML tags asits result. Thus, the development of a web page required the developer to code aprogram that would output the tags to be rendered by the browser. Again,developers would also still have to manage the Post and Get communicationhighlighted above.Java Server PagesIn order to move away from this programmatic view of web page development,the next step in the evolution brought us to Java Server Pages (JSP). These were“special” tags that could be embedded into a web page. These tags were used bythe JSP container to generate servlets, that in turn generated the markup. So, youhad the concepts of developers who could develop JSP tags, and possibly adifferent set of developers who could use the tags via JSTL (JSP Standard TagLibraries).However, this still represented a “tag” based view of UI development and stillrequired the UI developer to understand the intricacies of HTTP protocols and tomanage state.Thus, JSF finally brings the development of web UIs to the stage where developerscan work with visual controls that support an event model and allow visual editingthrough IDEs such as Oracle JDeveloper.JSF In the CommunitySo, being a ratified standard, anyone can develop their own set of JSF componentsfor use, and anyone could implement their own JSF runtime on which thosecomponents run. And that is what we are seeing in the wider community.Introducing Java Server Faces (JSF) to 4GL DevelopersPage 5

Oracle’s contributionOracle is one of the leading expert groups involved in the JSF specification,contributing their experiences from their own web framework used by the OracleApplications developers: UIX (User Interface XML). As a result of the work onthe specification, the library of UIX components was redeveloped as standard JSFcomponents. This set of components is called ADF Faces and can be used on anyruntime implementation of JSF.Being committed to the open source community, Oracle has also donated theirADF Faces implementation to the Apache community, and within this communitythis offering is called Trinidad.Contribution from othersSun, who are also involved in the JCP, provide a reference implementation for theJSF framework (the environment on which the JSF components run) and that nowappears in the Java Enterprise Edition (EE) 5.MyFaces, from the Apache community, provide both a 1.1 referenceimplementation as well as a component library. Other offerings include Glassfish,which is an open source implementation of Java EE 5 application server andcontains a JSF 1.2 implementation.The bottom line is components are standardized within JSF and you can use anycomponent from any vendor and mix and match them as required.For the remainder of this paper we willstudy and use the ADF Faces set ofcomponents; although the general pointscould apply to any JSF implementation.UNDERSTANDING JSFSo, now with an understanding of the need for a component based solution, thenext step is to look at these components and what features they offer.Introducing the componentFigure 1 shows a small sample of some of the ADF Faces components. Each webpage in your application will be constructed from components. Components willtypically be nested inside other components (called layout components orcontainers) to provide the required layout.Introducing Java Server Faces (JSF) to 4GL DevelopersPage 6

Figure 1 – ADF Faces componentsThe component architectureEach component is typified by three parts: attributes, behavior and renderers.AttributesEach component has a number of attributes associated with the component. Forexample, a button will have an attribute text that defines the text label that appearson the button; or a background-color attribute to define the background color.BehaviorThe component defines a number of actions that control the behavior of thatcomponent. For example, a button provides a valueChange event on which adeveloper associates code.RenderersThe component itself has attributes and behavior as indicated above but that saysnothing about how the component will actually look. That is the responsibility ofthe renderer. It is the job of the renderer to realize the component as defined as aconcrete screen instruction – e.g. in the case of a browser application – a fragmentof HTML mark-up.JSF UI components are not limited togenerating markup. For example UIComponents can also render binary datasuch as an image streams or differentHaving separate (or pluggable) rendering is one of the most compelling features ofJSF. The fact that the component behavior is de-coupled from the way it isdisplayed means that the same UI component can be displayed differently – forexample, depending on the device to which it is rendered.document types such as SVG, PDF andWord.Introducing Java Server Faces (JSF) to 4GL DevelopersPage 7

Supporting the componentHowever, the component does not live in isolation. The JSF runtime provides anumber of features to support the components.Managed beansThe managed bean is simply a Java object that provides integration between the UIcomponent and the data object the component is displaying. You can define thescope of these objects by indicating that they exist for the lifetime of theapplication, when only requesting a web page, or a session covering a number ofweb pages.Expression LanguageExpression Language (EL) is a scripting language that is part of the JSF runtimeand provides simplified expressions for accessing the data, managed beans and thevarious properties of the components. EL is a very powerful feature of JSF. Forexample, a component attribute (such as required) can be set by an EL expressiondepending on the value of data in a backing bean:#{emp.MaritalStatus ’single’}So if the value of MaritalStatus is “single” (and so the expression evaluates as true)then the required attribute will be set to true.Oracle ADF uses EL as the language to bind the UI components to the underlyingdata.Navigation caseThe JSF framework allows developers to define a set of rules that define thenavigation between pages. By default, this is defined in a file called faces-config.xmland is covered later in this paper.LifecycleThe JSF Request Processing Lifecycle (more commonly referred to as JSF lifecycle)is, as the name suggests, the various stages of processing in the life of a specific JSFrequest. At certain points in the JSF lifecycle specific actions will happen; whetherit is the component retrieving its current state, or rendering the component.A simple component exampleSo, in order to understand how each of these “parts” works as part of the whole,lets look at a simple case of a JSF text field component on a web page.Introducing Java Server Faces (JSF) to 4GL DevelopersPage 8

For simplicity, some tags have beenomitted.Figure 2 – Simple exampleIf you change from the design view of the page to the code view in the JDevelopervisual editor, you can see the source JDeveloper has created for you. There aretwo tags in the source code: f:view h:inputText The first is the top-level container in which all the UI components will appear. JSFholds the definition of the page in a component tree (which can be manipulated atruntime) and f:view encapsulates this components tree. h:inputText is a UI component in this tree and represents the input text field.Today the implementations of JSF happensHiding the implementation detailsto use JSP as a carrier technology. That is,Note that the input field has a property required which is set to true, and a propertyvalue, which is being resolved by an EL expression via a managed bean. However,there is absolutely no detail of how the component implements the properties or infact, how the component actually renders itself.the page definitions are JSP pages and theJSF components are expressed as JSP taglibraries. This however is a convenience, itmeans that conventional HTML / JSPeditors and IDEs can be used to design JSFpages. JSF itself makes no assumptionsabout the format of the page definition.So this component could render itself using HTML markup up if displaying in abrowser, WML (Wireless Markup Language) if displaying on a mobile device, orpossibly even some hybrid of markup and JavaScript (refer to Ajax, covered later).And that is the beauty of JSF to the business developer, the implementation detailof the UI control is hidden. The component simply exposes functionality andfeatures (as a UI component would in Visual Basic or Oracle Forms).Introducing Java Server Faces (JSF) to 4GL DevelopersPage 9

The event modelThe next step is to consider how the UI component initiates and reacts to UIactions or events such as pressing a button or selecting a value from a list.JSF provides an event model that supports three types of events.Action eventsAn action event in analogous to a WhenButton-Pressed trigger in Oracle Forms.An action event occurs when a JSF UI component, like a button or link, is clicked.Figure 3 shows a simple JSF page consisting of an input field, a button and anoutput field, which will display the data from the input field concatenate with thestring “hello”.Figure 3 – Simple event exampleBy double-clicking on the button,JDeveloper will automatically create aplaceholder for your code. JDeveloper willJDeveloper allows you to add a method to the Action attribute, which will executethe following code (held in a managed bean)public String buttonPressed action() {also create a backing bean for you and// Add event code here.accessor methods for getting and settingthe value of the UI components.String inputText ).setValue(inputText " hello!");;Note that this method returns a String, inreturn null;this case null. The importance of thisstring is discussed later in the navigation}sectionValue change eventsInput UI components such as input text fields have two events that are triggeredwhen changing data. A ValueChangeListener fires when a value in the field haschanged and Validator fires to validate the data entry. Again, JDeveloper providesIntroducing Java Server Faces (JSF) to 4GL DevelopersPage 10

a simple dialog to define the name of the method, the managed bean in which themethod is placed and will generate the correct method signature (Figure 4)Figure 4 – Creating a valueChangeListenerPhase eventsPhase events execute at specific instances in the JSF lifecycle, allowing you to addyour own code into the JSF lifecycle at points such as validation phase, or updatingthe model with values phase.The significant point for any of these events is not what you can code, but insteadwhat you DON’T have to code. There is no need to process the HTTP request to check what event israised. There is no need to process the HTTP request to find out what value wastyped into the input text field There is no processing the HTTP response to set the value of the outputfield. This is done be setting an attribute on the output text field.Introducing Java Server Faces (JSF) to 4GL DevelopersPage 11

The JSF framework provides a layer of abstraction to deal with the “plumbing” ofassociating an action with a piece of code and allowing to code to access attributesof the components.The page flowAs well as defining a framework for components on a page, JSF also defines aframework for managing the flow between application pages. So, performing aparticular action on a page results in navigation to another web page.Introducing faces-config.xmlNote that the faces-config.xml file containsmore information than just the navigationrules. As an introduction to JSF, yourprimary involvement with this file will bedefining navigation but it also used tospecify managed beans, render kits,converters and validators.As you would expect, JSF handles the flow of your application through the webpages with minimum of coding on the developer’s part. Instead, an XML filedefines what action on a specific page results in navigation to another specificpage. This XML file is called faces-config.xml.Figure 5 shows an example faces-config.xml file with a navigation case on thebrowserCustomers page. An edit action would result in navigation to the editCustomerspage, while a showOrders action would result in navigation to the customerOrders webpage.Figure 5 – Faces-config.xmlIntroducing Java Server Faces (JSF) to 4GL DevelopersPage 12

However, JDeveloper makes management of this file even easier by providing avisual editor for defining and visualizing the page navigation rules.Figure 6 – Faces-config.xmlThe action attributeIn order to define which UI component actually raises the action you simply setthe action property on the component. This is the same property that wasdiscussed earlier for defining the method to be executed on pressing a button. Theaction property can take the name of a navigation case on the diagram or the nameof a method – which is why

Nov 07, 2006 · Introducing Java Server Faces (JSF) to 4GL Developers Page 5 Before JSF It is difficult to see how far JSF has raised the bar for Java web application UIs without first being aware of the development experience (or lack of) that was the catalyst for the simpler UI component b

Related Documents:

Building JavaServer Faces Applications 7 JSF – A Web Framework JSR 127 – JSF specification v1.1 JSF 1.2 in progress (JSR 252) JSP 2.1 (JSR 245) will align with JSF JSF spec lead was the Struts architect JavaServer Faces technology simplifies building user interfaces for JavaServer

JSF has nothing to do with JSP per se. JSF works with JSP through a JSP tag library bridge. However, the life cycle of JSF is very different from the life cycle of JSP. Facelets fits JSF much better than JSP because Facelets was designed with JSF in mind, whereas integrating JSF and JSP has

What is JSF? Java Server Faces Java specification for building component-based user interfaces for web applications. It gives you the tools to communicate with java backing beans. JSF has all the javascript behind the scenes, creates the endpoints from JSF managed beans, and wires it all together. Agility. D

JSF i About the Tutorial Java Server Faces (JSF) is a Java-based web application framework intended to simplify development integration of web-based user interfaces. JavaServer Faces is a standardized display technology, which was formalized in a specification through the Java Community Process.File Size: 1MB

JSF includes a set of predefined UI components, an event-driven programming model, and the ability to add third-party components. JSF is designed to be extensible, easy to use, and toolable. This refcard describes the JSF development process, standard JSF tags, the JSF expressi

java.io Input and output java.lang Language support java.math Arbitrary-precision numbers java.net Networking java.nio "New" (memory-mapped) I/O java.rmi Remote method invocations java.security Security support java.sql Database support java.text Internationalized formatting of text and numbers java.time Dates, time, duration, time zones, etc.

Java Version Java FAQs 2. Java Version 2.1 Used Java Version This is how you find your Java version: Start the Control Panel Java General About. 2.2 Checking Java Version Check Java version on https://www.java.com/de/download/installed.jsp. 2.3 Switching on Java Console Start Control Panel Java Advanced. The following window appears:

An Introduction to Effective Field Theory Thinking Effectively About Hierarchies of Scale C.P. BURGESSc. i Preface It is an everyday fact of life that Nature comes to us with a variety of scales: from quarks, nuclei and atoms through planets, stars and galaxies up to the overall Universal large-scale structure. Science progresses because we can understand each of these on its own terms, and .