Biography Java Server Faces In Action Pdf


Thursday, May 30, 2019

sion of this book (available in PDF) as well as the print version. All of these people worked hard to make JavaServer Faces in Action a quality product. Lastly . JavaServer Faces in Action is an introduction, a tutorial, and a handy reference. With the help of many examples, the book explains what JSF is, how it works. JavaServer Faces (JSF) is a Java specification for building component-based I' m sure you know hot to implement such an easy action, but just to follow along.

Java Server Faces In Action Pdf

Language:English, Spanish, Arabic
Genre:Politics & Laws
Published (Last):06.10.2015
ePub File Size:29.79 MB
PDF File Size:10.81 MB
Distribution:Free* [*Regsitration Required]
Uploaded by: TYSON

Geary, David M. Core JavaServer faces / David Geary, Cay Horstmann.—2nd ed. slightly more efficient to use a JSP forward action instead. Create a page. 3 The JavaServer Faces Request Processing Lifecycle. .. Using a PhaseListener to Observe the Faces Lifecycle in Action Working. Java Server Faces (JSF) is a Java-based web application framework JavaServer Faces is a standardized .. Resolving Navigation Based on from- action.

No specification changes. The FacesServlet processes requests, loads the appropriate view template, builds a component tree, processes events, and renders the response typically in the HTML language to the client. The state of UI components and other objects of scope interest is saved at the end of each request in a process called stateSaving note: transient true , and restored upon next creation of that view.

Either the client or the server side can save objects and states. Ajax is a combination of web development techniques and technologies that make it possible to create rich user interfaces.

The JSF Expression Language

This has changed, however: Because JSF supports multiple output formats, Ajax-enabled components can easily be added to enrich JSF-based user interfaces.

The JSF 2. JSF 2 includes support for graceful degradation when JavaScript is disabled in the browser. It reached its end-of-life in June This eliminates the life-cycle conflicts that existed with JSP, forcing workarounds by Java developers. Navigation has been simplified, removing the need for faces-config. The latest JSF release has built-in support for handling resources like images, CSS and Javascript, allowing artifacts to be included with component libraries, separated into JAR files, or simply co-located into a consistent place within the Web application.

How to download a file using JSF 2 action

This includes logical naming and versioning of resources. JSF 2. Even when you are frequently evaluating your implementation against your intended architecture which is highly recommended to do! This stipulates for your analysis tools to understand these technical aspects by evaluating proprietary annotations, metadata and configuration artifacts.

The following sections discuss three scenarios commonly encountered in almost every web application.

Passing information to handlers Consider a simple view related to a single Managed Bean. Further, think about a Command Button triggering an action method. How can the action method know about the command button it was triggered from?

Introduction to JavaServer Faces 2.x

And even more interesting: How can the context in which the button was pressed also be passed on to the method? A simple example: Figure 1: Example 1 Regardless which one of the h:commandButtons is pressed, they are all triggering the same action method.

The method contains some logic to process the respective set of data displayed in the tables rows.

But how exactly does the method know which set of data it is to process? Lets take a look at the view definition for this example Example 1: View Definition for Example 1 This is a standard task and encountered in almost every web-application. The following sections discuss some approaches to solve the problem described above. Setting a property on the Managed Bean An easy solution is to simply fill a certain property in the managed bean.

Your Managed Bean may contain a property named "selected" to hold the set of data that was selected by the user when clicking the h:commandButton. Since JSF 1.

When using the f:setPropertyActionListener within a component, an Action Listener is created by the framework. This Action Listener fills the targeted value of the Managed Bean with a given value. The above example using an f:setPropertyActionListener looks like this Example 2: View Definition for Example 1 using f:setPropertyActionListener With the implicitly created Action Listeners filling the property in the Managed Bean, all you need to do to provide availability of the selected data in the Action Method is to simply access the beans "selected" property Example 3: Action Method in Backing Bean for Example 1 Although very simple and handy this solution has some drawbacks: Selected values need to be all of the same type With lots of different selections on the same page, your Managed Bean may grow quickly, resulting in reduced cohesion and thus, more important, poor maintainability.

Adding parameters to the command component The following approach eliminates the drawbacks of the prior one, by introducing parameters to the Command Component. While f:setPropertyActionListener requires to be placed at least somewhere within a component derived from ActionSource, every component derived from UIComponent which is true for every component represented by a tag in views is capable of carrying parameters. By adding the selected dataset as parameter to the h:commandButton, this parameter is available whenever you are dealing with this component.

Action Events refer to the component triggering the event, in this case the h:commandButton. Having Access to the component, all parameters are accessible, so all you need to do is to call the components getChildren method to access the nested components — including the nested parameters.

Example 4: View Definition for Example 2 using f:param Please note that since the h:commandButton may contain multiple parameters, the Listener is responsible of checking for the parameter name to avoid evaluation of wrong parameters. The major drawback of this solution is that it is code intensive.

You have to access the component and need to write some logic to traverse its children. Keep in mind that components may also have further child components besides f:param, therefore you also need to check for the correct type of the nested child components. When dealing with multiple parameters you also need to distinguish them by name, which requires additional code. Since Action Listeners are used quite frequently, this approach can often be found, especially in Ajax-intensive applications.

Adding attributes to the command component A more convenient approach, due to reduction of required code, is to add the desired dataset as an attribute to the component instead of nesting it as a child parameter component. When adding objects as attributes to components, these objects are available through the components attribute map. The following code shows the above example using f:attribute instead of f:param Example 6: View Definition for Example 3 using f:attribute Example 7: Action Listener in Backing Bean for Example 3 The main differences between usage of f:attribute and f:param is that parameters are added to the closest UIComponent associated with a custom action, requiring f:param to be placed as child component somewhere underneath a component implementing the ActionSource interface.

While this is valid only for CommandComponents, attributes may be added to every kind of UI Component, e. Compared to the previous example, the Action Listener became pretty lean this time. The Listener in this example simply assumes that the parameter named "selected" is an instance of the Address class. Please note that this may lead to errors during runtime when changing the attributes value in the view definition to another EL expression referencing a different type.


Passing values to Converters and Validators The benefit of Validators or Converters is often increased by enabling them to deal with parameters. It is worth thinking about a dedicated Validator class to keep your Managed Beans slim and maintainable whenever a Validator contains a lot of logic.

But even if you decide to keep validation in the Managed Bean, passing parameters as described in the previous two sections is an option to keep your code a bit smarter by simply attaching an f:attribute to the component. You can access the attribute within your validation method via the component since it is passed as an argument to the validation method.

Validation methods give developers access to all the information needed, as their signature is like public void validate FacesContext ctx, UIComponent component, Object toValidate The same principle can be applied to Converters since the component is passed as argument in both methods, getAsString … and getAsObject ….

Passing Values in Tables So far the concepts for passing values to handlers were applied within h:dataTables. Passing values to handlers is easily achieved by placing a command component in a table column. Clicks on the command component may trigger an Action Method or Action Listener, the information about which data row to process may be passed as attribute or parameter.

The following code shows an example with an ActionListener using an Attribute to describe the selected table row. The preceding example used a value binding to a collection containing the data to display.

Using a reference to a DataModel instance instead of a collection offers a more convenient way to access the selected data set Example View Definition for Example Example Backing Bean using a DataModel in Example 5 As you can see in the code example above, JSF takes care of informing the data model which distinct data set was selected.

When an ActionSource is triggered, JSF takes notice about the related element of the wrapped data and updates the table model. Please note the difference between the ActionListener in Example 4 and the ActionMethod in this example. The example in section one described how the tag can be used to set a managed bean property. The same approach can be used to set a property on a managed bean that belongs to the next view to display.

Example View Defintion of first view in Example Click the web browser icon in the documentation window to open the Javadoc in an external web browser.

JSF also synchronizes user input with application objects, automating another tedious aspect of web development. Thankfully, the number of people actually implementing the spec is relatively small compared to those using those implementations, but as it turns out, knowing the specification in detail is still helpful in order to use it.

Click Enter. In the same place where you structure your HTML, you also place the logic what parts of the UI should get updated on an action. Of course, this means that any components you develop will also be able to plug into tools without too much additional work.

Random into the class.

Click Generate.