Mastering omnifaces a problem

664 417 0
Mastering omnifaces a problem

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Mastering OmniFaces Written by: Anghel Leonard and Constantin Alin Reviewed by: Bauke Scholtz and Arjan Tijms Glasnevin Publishing, 2nd Floor, 13 Upper Baggot Street, Dublin 4, Ireland www.glasnevinpublishing.com This edition published in 2015 by Glasnevin Publishing © Anghel Leonard and Constantin Alin 2015 All rights reserved No part of this book may be reproduced or utilised in any form or by any means electronic or mechanical including photography, filming, recording, video recording, photocopying, or by information storage and retrieval system and shall not, by any way of trade or otherwise, be lent, resold or otherwise circulated in any form of binding or cover other than that in which it is published without prior permission in writing from the publisher The moral rights of the author have been asserted All trademarks that appear in the book are trademarks of their respective owners Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark Where such designations appear in this book, they have been printed with initial caps The author and publisher of this book have used their best efforts in preparing this book These efforts include the development, research and testing of the theories and computational models given in the book The author and publisher make no warranty of any kind, expressed or implied, with regard to any text, models, program code or algorithms contained in this book The author and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of this text, models, program code or algorithms ISBN: 978-1-908689-29-0 A CIP catalogue record for this book is available from the British Library Papers used by Glasnevin Publishing are from well managed forests and other responsible sources Glasnevin Publishing books are available at special quantity discounts for use in educational courses or for use in corporate training programs For more information, please email info@glasnevinpublishing.com JavaTM is a registered trademark of Oracle and/or its affiliates Contents Preface About the Authors About the Reviewers Acknowledgements Chapter 1: OmniFaces Components 1.1 OutputLabel 1.2 Param 1.3 OutputFormat 1.4 Messages 1.5 OnloadScript 1.6 DeferredScipt 1.7 Highlight 1.8 ViewParam 1.9 Form and IgnoreValidationFailed 1.10 Cache 1.11 CommandScript 1.12 ResolveComponent 1.13 ResourceInclude 1.14 GraphicImage 1.15 ComponentIdParam 1.16 MoveComponent 1.17 Tree 1.18 ConditionalComment Chapter 2: OmniFaces Validators 2.1 JsfLabelMessageInterpolator 2.2 ValueChangeValidator and ValueChangeConvertor 2.3 RequiredCheckbox Validator 2.4 Validate Bean 2.5 ValidateUniqueColumn 2.6 ValidateXxx Chapter 3: OmniFAces Tag Handlers 3.1 Convertor/Validator 3.2 ImportConstants/ImportFunctions 3.3 ViewParamValidationFailed 3.4 EnableRestorableView 3.5 MassAttribute 3.6 MethodParam 3.7 TagAttribute Chapter 4: OmniFaces Convertors 4.1 GenericEnumConvertor 4.2 SelectItemsConvertor and SelectItemsIndexConvertor Chapter 5: OmniFaces Exception Handlers 5.1 FullAjaxExceptionHandler 5.2 FacesMessageExceptionHandler Chapter 6: OmniFaces Contexts 6.1 OmniPartialViewContext Chapter 7: OmniFaces Resource Handlers 7.1 CDNResourceHandler 7.2 UnmappedResourceHandler 7.3 CombinedResourceHandler Chapter 8: OmniFaces Event Listeners 8.1 InvokeActionEventListener 8.2 ResetInputAjaxActionListener Chapter 9: OmniFaces View Handlers 9.1 NoAutoGeneratedIdViewHandler Chapter 10: There’s More! Preface OmniFaces is a utility library for JSF and a comprehensive compendium of programming techniques, design patterns and recipes for JSF developers Mastering OmniFaces is targeted towards JSF page authors/developers that wish to use OmniFaces in their projects and JSF developers interested in going deep into the JSF API “bowels” in order to become real JSF masters When confronted with “unusual” JSF tasks (e.g fixing bugs, solve gaps, avoiding pitfalls, etc.) we often don’t have enough self confidence that we are the right person to complete the task, so we ask for professional help in different communities or “question and answer sites”, such as StackOverflow StackOverflow isn’t just casually mentioned here, as it seems that the OmniFaces project idea was “born” as a professional and unitary answer to the most popular questions/bugs/gaps reported on this site The professionals that picked up those reports from StackOverflow and answered/solved them via the OmniFaces project are Bauke Scholtz and Arjan Tijms Both Scholtz and Tijms are JSF Expert Group members directly involved in JSF development They constantly “scan” the JSF world for newly reported issues and are always open to receive new ideas/suggestions for improving OmniFaces and JSF In this way, OmniFaces is always up to date and is continuously getting better Moreover, OmniFaces is available under the Apache License 2.0, so it may be freely used, distributed, and modified In this book, we “dissect” OmniFaces 2.1 and we extract valuable lessons that will definitely give you a boost in the JSF field After you have read this book, you will say Wow, I knew so little about JSF before! Now, I’m able to solve tasks that I didn’t have a clue about in the past! As you will see, however, it is not easy to reach a high level of JSF knowledge Not everything will be easy to understand and assimilate, and many advanced techniques require hard work, patience, creativity and perseverance Whenever you are really stuck or you have a brilliant idea of how to improve the OmniFaces project, just contact us using the information in the Contact/Questions subsection below While reading this book, it would be great to also follow the pointed references These references come from http://omnifaces-fans.org/ and they cover different JSF fundamentals that couldn’t be covered in the book They are meant to supply mandatory information in order to understand a specific topic Moreover, the OmniFaces utilities references (also covered on http://omnifaces-fans.org/ ) are important to understand the OmniFaces shortcuts and to seriously increase your collection of JSF helpers For convenience, we have all these references collected in a ZEEF page available at https://omnifaces-utilities.zeef.com/anghel.leonard Chapter 10: There’s More! This final part is just a brief overview of the OmniFaces artifacts that were not covered in this book Some of them are slightly related to JSF, others will be deprecated or migrated to JSF 2.3, while for others we just didn’t have space They are presented by their category, and most descriptions are taken from OmniFaces Showcase CDI Under this category we have the following artifacts: Cookie - This is a CDI annotation introduced in OmniFaces 2.1 that can be used toinject a HTTP request cookie value from the current JSF context in a CDI managed bean It’s basically like @ManagedProperty(“#{cookie.cookieName.value}”) private String cookieName; in a “plain old” JSF managed bean.Beside CDI API, its implementation is based on Faces#getRequestCookie() utility method, which is further based on ExternalContext#getRequestCookieMap() Eager - This is a CDI annotation that provides the ability to eagerly instantiate application scoped beans The @Eager annotation can be applied to @RequestScoped , @ViewScoped , @SessionScoped and @ApplicationScoped beans, where @RequestScoped and @ViewScoped are for a specific URI/view FacesConverter - The @FacesConverter is by default not eligible for dependency injection by @Inject nor @EJB There is a workaround for EJB, but this is nasty and doesn’t work out for CDI Initially, this should be solved in JSF 2.2, but the support is expected to come back in JSF 2.3.MyFaces CODI has support for it, but it requires an additional @Advanced annotation OmniFaces solves this by implicitly making all FacesConverter instances eligible for dependency injection without any further modification, like as JSF 2.2 would initially do, hereby providing a transparent bridge of the code to the upcoming JSF 2.3 FacesValidator - idem with FacesConverter , but obviously for validators Param - The CDI annotation Param allows you to inject, convert and validate a HTTP request parameter in a CDI managed bean It’s basically like , but with the major difference that the injected HTTP request parameter is directly available during PostConstruct , allowing a much easier way of processing without the need for a or in the view ViewScoped - The CDI view scope annotation is intended for use in JSF 2.0/2.1 Just use it the usual way as all other CDI scopes Watch out with IDE autocomplete on import that you don’t accidentally import JSF’s own one Please note that the bean must implement Serializable , otherwise the CDI implementation will throw an exception about the bean not being passivation capable In JSF 2.2, you’re supposed to use JSF’s own new CDI compatible javax.faces.view.ViewScoped instead; not because this CDI view scope annotation is so bad, in contrary, but just because using the standard solutions should be preferred over alternative solutions if they solve the same problem Furthermore the OmniFaces 2.2 @ViewScoped will now be destroyed during HTML beforeunload FacesViews ExtensionlessURLs - FacesViews is a mechanism to use SEO-friendly extensionless URLs in a JSF application without the need to enlist individual Facelet source files in some configuration file As far as we understood (nothing official), this component is possible to be migrated to JSF 2.3 Filters HttpFilter - The HttpFilter is abstract filter specifically for HTTP requests.This is an implementation of javax.servlet.Filter CacheControlFilter - This filter will control the cache-related headers of the response Cache- related headers have a major impact on performance (network bandwidth and server load) and user experience (up to date content and non-expired views).This is an extension of the HttpFilter CharacterEncodingFilter - This filter will set the request body character encoding when not already set by the client Even though JSF2/Facelets uses by default UTF-8 everywhere, which is the best charset choice these days, JSF2/Facelets might fail to set it to UTF-8 when something else has set it to a different value before JSF2/Facelets gets the chance to set it during the restore view phase PrimeFaces 3.x for example is known to do that This is an extension of the HttpFilter FacesExceptionFilter - The FacesExceptionFilter will solve problems with exceptions thrown in JSF methods First, Mojarra’s FacesFileNotFoundException needs to be interpreted as 404, and second, root cause needs to be unwrapped from FacesException and ELException to utilize standard Servlet API error page handling This is an extension of the HttpFilter GzipResponseFilter - The GzipResponseFilter will apply GZIP compression on responses whenever applicable GZIP will greatly reduce the response size when applied on character based responses like HTML, CSS and JS, on average it can save up to ~70% of bandwidth This is an extension of the HttpFilter Managed Beans now - The built-in managed bean #{now} returns you the java.util.Date instance representing the current time startup - The built-in managed bean #{startup} returns you the java.util.Date instance representing the server’s startup time Render Kits Html5RenderKit - This HTML5 render kit adds support for HTML5 specific attributes which are unsupported by the JSF UIForm , UIInput and UICommand components But, JSF 2.2 supports defining custom attributes directly in the view via the http://xmlns.jcp.org/jsf/passthrough namespace or the tag So, is very possible that this artifact will be deprecated and probably, in version 3.0, removed It was already marked for this step Scripts FixViewState - This script fixes the JSF view state if necessary In Mojarra, it get lost on certain forms during certain AJAX updates (e.g updating content which in turn contains another form) Functions Arrays - Collection of EL functions manipulation: of:createArray() , of:createIntegerArray() , and of:contains() for array Converters - Collection of EL functions for data conversion: of:iterableToList() (with alternative of:iterableToModel() ), of:setToList() , of:mapToList() , of:joinArray() , of:joinCollection() , of:joinMap( and of:toJson() Dates - Collection of EL functions for date and time: of:formatDate() , of:formatDateWithTimezone() , of:addXxx() like of:addDays() , of:xxxBetween() like of:daysBetwe Numbers - Collection of EL functions for number formatting: of:formatBytes() , of:formatCurrency() , of:formatNumber() , of:formatNumberDefault() and of:formatPercent Objects - Collection of EL functions for objects Request - Collection of EL shortcut functions for obtaining information from the current HTTP request which isn’t directly available via #{request} and thus otherwise requires some string concatenating and/or substringing Strings - Collection of EL functions for string manipulation: of:abbreviate() , of:capitalize() , of:concat() , of:prettyURL() , of:encodeURL() , of:escapeJS() and Upcoming JSF 2.3 While JSF 2.2 was a milestone release with a lot of new features and several big tickets, the upcoming JSF 2.3 comes with more support for CDI, several improvements and bug fixes The JSF development team (including Bauke Scholtz and Arjan Tijms EG members) aim is to provide support for: Injecting artifacts as request cookie map ( @RequestCookieMap ), view map ( @ViewMap ), session map ( @SessionMap ), application map ( @ApplicationMap ), faces converter, faces validator, faces behavior, view root, faces context, external context, etc Iterable interface in UIData (e.g )and UIRepeat (e.g ) PostRenderViewEvent new event When the project stage is Production (which incidentally is the default stage) the Facelets refresh period is -1 (no refresh) JSF 2.3 will be finalized in 2016 and be part of Java EE 8 (JSR-366) Upcoming OmniFaces 3.0 It looks like the next milestone release of OmniFaces will be 3.0 Directly from OmniFaces creators: As to OmniFaces 3.0, we actually don’t have anything concretely planned for specifically that version other than just upgrading the minimum requirement to JSF 2.3 (and Java 8 and CDI 1.2), and removing already-deprecated stuff, and deprecating existing stuff which ended up in JSF 2.3, and maybe migrating/renaming some packages/classes/methods for reusability/clarity We will surely take the opportunity to rewrite code here and there to utilize the Java lambda/stream awesomeness where possible As to new things, as usual those will directly come in first next OmniFaces version when we have the opportunity There are so far no new things in schedule which doesn’t fit in an OmniFaces 2.x I (Bauke Scholtz) have somewhere a half-finished proof of concept for JSR356 websocket based JSF push component which I need to finish sometime - it was after all not really trivial; pushing is easy, but receiving in e.g a view scoped bean is tricky with regard to triggering the right bean instance; CDI events are promising though, but this forces a CDI dependency It may end up in JSF 2.3, but if it doesn’t make to it, it may end up in OmniFaces That may already be 3.0 at that point Also Available from Glasnevin Publishing The Beginner’s Guide to Android Game Development By James Cho ISBN-13: 978-1908689269 Android Game Development Made Easy If you’ve always wanted to make Android games but didn’t know where to start, this book is for you Whether you are an absolute beginner with no programming experience or an experienced Java developer wanting to get started with game development, this comprehensive book will help you accomplish your goals and teach you how to build your own games from scratch - no game engines needed In this beginner-friendly guide, you will find focused, step-by-step approaches designed to help you learn and practice one fundamental concept at a time You will study Java and write object-oriented applications You will experiment with the building blocks of Android and create fun, interactive 2D games with touch controls You will even learn how to integrate social features such as a global leaderboard and publish your game to be shared with the billion Android users across the world This book provides access to an extensive library of sample Java and Android game projects via its companion website so that you can continue learning on your own and grow as a game programmer With this up-to-date guide in your hand, you will be able to successfully navigate common pitfalls and get up and running with your own projects in no time Also Available from Glasnevin Publishing Programming the Finite Element Method using Java and Android By Bryan J Mac Donald ISBN-13: 978-1908689184 This book provides an introduction to programming the finite element method in Java for students, researchers and engineers who are reasonably familiar with the finite element method and want to learn how to write their own finite element code using Java This book is written as an introductory text and it is assumed that the reader has little or no knowledge of object‐oriented programming or Java By concentrating on line elements, specifically structural trusses, it is possible to make the code very simple and relatively easy to understand The philosophy of the book is to teach the reader how to write a very simple object‐oriented finite element code in Java, with the understanding that once the reader has these skills they should easily be able to extend the code to more complex problems As newcomers to programming find dealing with command line executed software frustrating and challenging; the Android operating system is used to develop a graphical user interface to allow the reader to interact with their Java code Android provides a relatively simple (and very well supported) platform for coding a user interface and means that the finished application will work on any Android device (smartphone, tablet, etc.) The book is supported by a webpage which contains the source code for the Android app and other helpful material The Android app that is detailed in the book is also available for download

Ngày đăng: 12/05/2017, 13:14

Từ khóa liên quan

Mục lục

  • Preface

  • About the Authors

  • About the Reviewers

  • Acknowledgements

  • Chapter 1: OmniFaces Components

    • 1.1 OutputLabel

    • 1.2 Param

    • 1.3 OutputFormat

    • 1.4 Messages

    • 1.5 OnloadScript

    • 1.6 DeferredScipt

    • 1.7 Highlight

    • 1.8 ViewParam

    • 1.9 Form and IgnoreValidationFailed

    • 1.10 Cache

    • 1.11 CommandScript

    • 1.12 ResolveComponent

    • 1.13 ResourceInclude

    • 1.14 GraphicImage

    • 1.15 ComponentIdParam

    • 1.16 MoveComponent

Tài liệu cùng người dùng

Tài liệu liên quan