- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
The same page on different devices, with different RenderKits in Java
The same page on different devices, with different RenderKits QR-Code Generator In Java Using Barcode creation for Java Control to generate, create QR image in Java applications. QR Code Reader In Java Using Barcode scanner for Java Control to read, scan read, scan image in Java applications. 11: Generating Barcode In Java Using Barcode generator for Java Control to generate, create barcode image in Java applications. Bar Code Reader In Java Using Barcode decoder for Java Control to read, scan read, scan image in Java applications. Building Custom UI Components
Encode QR Code JIS X 0510 In Visual C# Using Barcode generation for .NET framework Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications. QR Code ISO/IEC18004 Creator In .NET Framework Using Barcode encoder for ASP.NET Control to generate, create Denso QR Bar Code image in ASP.NET applications. PhaseListeners are described in more detail in 9, but for now just know that a PhaseListener is an interface you implement when you want to have the system call back your application code as a request moves through the JSF lifecycle In this case, we want our PhaseListener to inspect the User-Agent header after the restore view phase and set the RenderKit appropriately, on a per-request basis, as shown here in this inner class: Denso QR Bar Code Generation In Visual Studio .NET Using Barcode generator for VS .NET Control to generate, create QR Code image in Visual Studio .NET applications. QR Code ISO/IEC18004 Maker In Visual Basic .NET Using Barcode creation for .NET framework Control to generate, create Quick Response Code image in VS .NET applications. public class RenderKitSelectorPhaseListener implements PhaseListener { public PhaseId getPhaseId() { return PhaseIdRESTORE_VIEW; } Creating Data Matrix In Java Using Barcode generator for Java Control to generate, create ECC200 image in Java applications. USS Code 39 Maker In Java Using Barcode generator for Java Control to generate, create Code39 image in Java applications. PART II
Encode Barcode In Java Using Barcode drawer for Java Control to generate, create bar code image in Java applications. Printing DataMatrix In Java Using Barcode encoder for Java Control to generate, create DataMatrix image in Java applications. private void setRenderKitFromUserAgent(FacesContext context, String userAgent) { // To implement this kind of feature in a robust way requires a lot // of research and will result in lots of heuristics This version // is very simple and just looks for the strings iPod or iPhone // to determine if the User-Agent is coming from an iPhone or iPod // touch if (userAgentcontains("iPod") || userAgentcontains("iPhone")) { contextgetViewRoot()setRenderKitId( AppleMobileRenderKitRENDER_KIT_ID); } } public void afterPhase(PhaseEvent event) { setRenderKitFromUserAgent(eventgetFacesContext(), eventgetFacesContext()getExternalContext() getRequestHeaderMap()get("User-Agent")); } public void beforePhase(PhaseEvent event) { } } USS Code 93 Creation In Java Using Barcode printer for Java Control to generate, create Code 93 Extended image in Java applications. Generating UPC A In VB.NET Using Barcode drawer for .NET Control to generate, create GTIN - 12 image in VS .NET applications. This simple phase listener is declared to the runtime in the faces-configxml file
Data Matrix Drawer In C# Using Barcode generator for Visual Studio .NET Control to generate, create Data Matrix ECC200 image in .NET applications. Paint Code 128 Code Set A In None Using Barcode drawer for Software Control to generate, create Code 128 image in Software applications. <lifecycle> <phase-listener>comjsfcomprefcomponentsrendererapplemobile RenderKitSelectorPhaseListener</phase-listener> </lifecycle> Printing Bar Code In Visual Studio .NET Using Barcode generation for ASP.NET Control to generate, create bar code image in ASP.NET applications. Generate GTIN - 13 In Visual Studio .NET Using Barcode maker for Visual Studio .NET Control to generate, create EAN13 image in VS .NET applications. This code exposes a very important subtlety with our choice of setting the RenderKit on a per-request basis We made this choice because we didn t want to push the awareness of which RenderKit to use into the session This is a trade-off between server memory and runtime speed performance In this case we chose to save server memory (and complexity) in favor of a sacrificing a little runtime speed The subtlety comes from how we must take action in the afterPhase( ) method of restore view because this is the earliest time in the lifecycle when contextgetViewRoot( ) returns non-null We need access to the UIViewRoot so that we can set its renderKitId property At this point, we have a working phase listener that sets the RenderKit to use on this run through the lifecycle Recognize Barcode In Visual Basic .NET Using Barcode Control SDK for .NET Control to generate, create, read, scan barcode image in .NET applications. Creating EAN 13 In None Using Barcode creator for Font Control to generate, create GS1 - 13 image in Font applications. Part II: Extending JavaServer Faces
Decorating the HTML_BASIC RenderKit
Now we will show how to decorate the standard HTML_BASIC RenderKit, which all JSF implementations must provide This will give us the ability to provide a RenderKit that is exactly the same as the standard one, but only override specific Renderers to provide content for a specific client device type package comjsfcomprefcomponentsrendererwrapper; import import import import import import import import javautilHashMap; javautilMap; javaxfacesFactoryFinder; javaxfacescontextFacesContext; javaxfacesrenderRenderKit; javaxfacesrenderRenderKitFactory; javaxfacesrenderRenderKitWrapper; javaxfacesrenderRenderer; public abstract class BaseRenderKitWrapper extends RenderKitWrapper { private RenderKit basic; private Map<String, Map<String, Renderer>> myFamilies = new HashMap<String, Map<String, Renderer>>(); public BaseRenderKitWrapper() { RenderKitFactory factory = (RenderKitFactory) FactoryFindergetFactory(FactoryFinderRENDER_KIT_FACTORY); basic = factorygetRenderKit(FacesContextgetCurrentInstance(), "HTML_BASIC"); } @Override public RenderKit getWrapped() { return basic; } @Override public void addRenderer(String family, String rendererType, Renderer renderer) { Map<String, Renderer> renderersForFamily = myFamiliesget(family); if (null == renderersForFamily) { renderersForFamily = new HashMap<String, Renderer>(); myFamiliesput(family, renderersForFamily); } renderersForFamilyput(rendererType, renderer); } @Override public Renderer getRenderer(String family, String rendererType) { Renderer result = null; Map<String, Renderer> renderersForFamily = myFamiliesget(family); if (null != renderersForFamily) { result = renderersForFamilyget(rendererType); 11: Building Custom UI Components
if (result instanceof BaseRendererWrapper) { ((BaseRendererWrapper)result)setBaseRenderKit(this); } } if (null == result) { result = basicgetRenderer(family, rendererType); } return result; } public Renderer getBaseRenderer(String family, String rendererType) { Renderer result = null; result = basicgetRenderer(family, rendererType); return result; } } PART II
This class extends javaxfacesrenderRenderKitWrapper The wrapper concept is explained in 13 This concept boils down to extending a wrapper base class, overriding the abstract getWrapped( ) method, and then overriding only the minimum number of other methods as needed In the constructor, we obtain a reference to the threadsafe singleton HTML_BASIC RenderKit, which we also return from the getWrapped( ) method The other methods we override are getRenderer( ) and addRenderer( ) These two methods fulfill the basic contract of a RenderKit as a data structure that stores Renderer instances, as shown in the preceding HtmlHelloWorldRenderer example The data structure within a RenderKit implementation is commonly implemented as a two-level Map The keys in the outer map are component family identifiers Each key in the outer map is associated with an inner Map, in which the keys are renderer-type identifiers and the values are the actual Renderer instances In the preceding code, this data structure is the myFamilies instance variable In getRenderer( ) and addRenderer( ), we check myFamilies first when access to a Renderer is needed, and if no matching Renderer is found there, we call through to the RenderKit returned from getWrapped( ) In this way, we can override as many or as few of the Renderers from the standard HTML_BASIC RenderKit as needed Now that you understand how our RenderKit decoration works, it is time to show a concrete BaseRenderKitWrapper subclass, called AppleMobileRenderKit package comjsfcomprefcomponentsrendererapplemobile; import comjsfcomprefcomponentsrendererwrapperBaseRenderKitWrapper; import javaxfacescontextFacesContext; public class AppleMobileRenderKit extends BaseRenderKitWrapper { public static final String RENDER_KIT_ID = "HTML_APPLEMOBILE"; public static final String RESOURCE_LIBRARY_NAME = "applemobile"; static String getRequestPathForResource(FacesContext context, String resourceName) { String result = null; String expressionString = "#{resource['" + RESOURCE_LIBRARY_NAME + ":" + Part II:
|
|