12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 11 ■ PAGES AND COMPONENTSItems in this resource identifier in [] are optional. The local prefix consists of the language codefollowed by an optional country code (en, en_US, pt, pt_BR). As this line indicates, you can add versioningto the library or the resource itself. Following are resource structures you might end up <strong>with</strong>:book.gifen/book.gifen_us/book.gifen/myLibrary/book.gifmyLibrary/book.gifmyLibrary/1_0/book.gifmyLibrary/1_0/book.gif/2_3.gifYou can then use a resource, such as this book.gif image, directly in the component or by specifying the library name (library="myLibrary"). The resource <strong>with</strong> the right localefor your client will get pulled automatically.Composite ComponentsAll the previously discussed components are part of JSF and come <strong>with</strong> any implementation that followsthe specification. Because JSF is based on reusable components, it provides a design that allows you toeasily create and integrate your own components or third-party components into your applications.Earlier, I mentioned that all components you’ve seen extend, directly or indirectly, thejavax.faces.component.UIComponent class. Before JSF 2.0, if you wanted to create your own component,you had to extend the component class that most closely represented your component (UICommand,UIGraphic, UIOutput, etc.), declare it in the faces-config.xml file, and provide a tag handler and arenderer. These steps were complex, and other web frameworks such as Facelets showed that it waspossible to create powerful components <strong>with</strong> less complexity. This is the point of compositecomponents: to enable developers to write real, reusable, JSF UI components <strong>with</strong>out any <strong>Java</strong> code orconfiguration XML.This new approach involves creating an XHTML page that contains components, and then usingthis page as a component in other pages. This XHTML page is then seen as a real component that cansupport validators, converters, and listeners. Any valid markup can be used inside of a compositecomponent, including the templating features. Composite components are handled as resources andtherefore must reside <strong>with</strong>in the new standard resource directories. Table 11-18 lists all the tags involvedin the creation and definition of a composite component.337

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!