Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 30 web apps error page error code 500 error code location WEB INF errorpages 500 xhtml location error page or this error page exception type java lang Throwable exception type location WEB INF errorpages 500 xhtml location error page Reference an image provided as an InputStream byte or data URI Most JSF novices know how to use the built in h graphicImage tag with the name and library attributes to load an image from the well known resources folder or from an external URL using the value or url attributes If not check out this article But what should be done when the image is not present at the end of a URL for example when it comes from a database a web service or a WebSocket In such cases the image usually comes as a byte array InputStream BLOB or other form In fact what about an image as a data URI OmniFaces provides the GraphicImage component which is an elegant solution for loading an image that comes as a byte array or InputStream and it is capable of extracting a data URI also The content type will be guessed based on the content header it supports the JPEG PNG GIF ICO SVG BMP and TIFF formats In addition OmniFaces supports a last modified time stamp which improves browser caching In addition SVG images can be loaded via modes including the ability to show only a part of an SVG image via viewBox There are many examples of displaying images provided from an external resource such as a servlet that can be handled elegantly by OmniFaces Deal with a ViewExpiredException A common issue in JSF consists of dealing with a ViewExpiredException When a user session expires such as when a session times out a logical view was removed from the logical views map or a session was programmatically invalidated a ViewExpiredException occurs OmniFaces provides a tag handler named Enable RestorableView which is capable of swallowing a ViewExpiredException and restoring the view I am here talking about session restoring not about session recovery which is a different challenge in JSF This tag handler can be used in a page by placing the o enableRestorableView tag in f metadata This allows us to instruct the view handler to re create the entire view whenever the view has been expired You simply write it like this f metadata o enableRestorableView f metadata Conclusion OmniFaces contains many other useful artifacts for JSF developers In this article you saw just a small part of what OmniFaces is capable of As development continues OmniFaces is becoming a more mature and powerful JSF utility library thanks to the work of Bauke Scholtz and Arjan Tijms who scan the JSF community for newly reported issues to solve In this way OmniFaces is always up to date on current issues As expected OmniFaces is open source under the Apache License 20 Enjoy article Anghel Leonard is a senior Java developer with many years of experience in Java SE Java EE and frameworks He has written numerous articles about Java as well as several books including Mastering OmniFaces Glasnevin Publishing
You must have JavaScript enabled to view digital editions.