itextsharp barcode vb.net An AJAX SpellCheck JSF Component in Java

Creation Data Matrix ECC200 in Java An AJAX SpellCheck JSF Component

An AJAX SpellCheck JSF Component
Data Matrix ECC200 Generation In Java
Using Barcode encoder for Java Control to generate, create ECC200 image in Java applications.
DataMatrix Reader In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
Similar to the previous AJAX example, this next example falls in line with the guiding philosophy in our usage of AJAX, which is to present to the page author the simplest possible usage model It therefore also hides all of the complexity of asynchronous JavaScript
Bar Code Encoder In Java
Using Barcode drawer for Java Control to generate, create barcode image in Java applications.
Decoding Bar Code In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
Part II:
Create Data Matrix 2d Barcode In C#
Using Barcode generation for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in .NET framework applications.
Generating Data Matrix ECC200 In Visual Studio .NET
Using Barcode drawer for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
Extending JavaServer Faces
ECC200 Encoder In .NET Framework
Using Barcode creator for .NET framework Control to generate, create Data Matrix 2d barcode image in VS .NET applications.
DataMatrix Maker In Visual Basic .NET
Using Barcode generator for VS .NET Control to generate, create ECC200 image in VS .NET applications.
code behind a Faces component Our next AJAX example component, SpellCheckTextArea, extends HtmlInputTextArea and provides a simple AJAX-enabled spell-checking facility The JSP usage for this is also very simple:
Create 1D Barcode In Java
Using Barcode generation for Java Control to generate, create 1D Barcode image in Java applications.
Bar Code Maker In Java
Using Barcode generation for Java Control to generate, create barcode image in Java applications.
<jcr:spellCheckTextArea cols="30" rows="15" value="#{userinterests}" />
UCC - 12 Generation In Java
Using Barcode creation for Java Control to generate, create GS1 - 12 image in Java applications.
Printing Code 128 Code Set C In Java
Using Barcode creation for Java Control to generate, create Code 128C image in Java applications.
This component renders a spell-checking panel beneath an HTML textarea input field, and allows the user to check the spelling of their text before submitting As before, the user is not required to put any <script> tags anywhere in the page to use this component When the user presses the Next button (as shown in Figure 11-6), an asynchronous request is made to the server, which causes a MethodBinding to be called This MethodBinding points to a method that takes a string and returns an array of suggested spellings For the sake of simplicity, <jcr:spellCheckTextArea> doesn t do anything fancy to highlight the incorrect word or dynamically replace it with the chosen suggestion This feature has nothing to do with Faces and therefore is left as an exercise for the reader Rather, the UI simply shows the current misspelled word and lists the suggestions in a simple table, as shown in Figure 11-6 Similar to the DirectorySearch example, the SpellCheckTextArea example also shows the power of combining Faces with AJAX techniques while delivering the same ease of development to the page author We ll now examine the high-level AJAX JSF elements of the SpellCheckTextArea example in more detail
Generating Case Code In Java
Using Barcode generator for Java Control to generate, create UPC Case Code image in Java applications.
Print Data Matrix In None
Using Barcode creator for Microsoft Word Control to generate, create DataMatrix image in Microsoft Word applications.
The AJAX Script Element for the SpellCheckTextArea Example
Data Matrix 2d Barcode Decoder In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
Print Barcode In VB.NET
Using Barcode encoder for VS .NET Control to generate, create barcode image in VS .NET applications.
In contrast to rendering AJAX script directly into the page from the component s encode( ) methods, the SpellCheckTextArea example uses a PhaseListener to deliver the AJAX script instead In this example, the delivered script is just a reference to an external JavaScript file It is also conditionally rendered such that only the first usage of the SpellCheckTextArea
ANSI/AIM Code 128 Creation In VS .NET
Using Barcode creator for .NET framework Control to generate, create Code 128 Code Set B image in VS .NET applications.
Painting Barcode In Objective-C
Using Barcode creation for iPhone Control to generate, create barcode image in iPhone applications.
FIGURE 11-6 The AJAX SpellCheckTextArea component
Barcode Generator In .NET
Using Barcode creation for ASP.NET Control to generate, create barcode image in ASP.NET applications.
ANSI/AIM Code 128 Printer In None
Using Barcode encoder for Software Control to generate, create Code 128B image in Software applications.
11:
Building AJAX JSF Components
PART II
FIGURE 11-7 Using a PhaseListener to render the AJAX JavaScript
component renders the script since the browser only needs one copy of the AJAX script in memory
Using a PhaseListener to Deliver the AJAX Script to the Client Since the AJAX script is just a file reference, in keeping with hiding the JavaScript from the page author, it would be nice to avoid requiring the page author to place the script file at some location on the server s filesystem Instead, the file will be referenced purely as a runtime resource such as SpellCheckTextArea ajaxScript At runtime this script resource will be resolved and the content will be delivered to the client leveraging the existing FacesServlet using a PhaseListener This approach, shown in Figure 11-7, allows you to bundle the actual AJAX script file into the same jar file in which the component itself is packaged, preserving the all-important JSF value proposition of drop the component jar into WEB-INF/lib of your application and you re ready to go Early in this book, there is an example of how to write a simple PhaseListener This example defines a SpellCheckPhaseListener that handles several different processing tasks, one of them being to render the AJAX script The SpellCheckPhaseListener needs to be notified only on the Restore View phase of the lifecycle, so its getPhaseId( ) method looks like this:
public PhaseId getPhaseId() { PhaseIdRESTORE_VIEW; }
Part II:
Extending JavaServer Faces
In the case of rendering the AJAX script, the afterPhase( ) event is acted upon during the Restore View phase:
public void afterPhase(PhaseEvent event) { // If this is restoreView phase and the viewId is the script view id if (-1 != eventgetFacesContext()getViewRoot() getViewId()indexOf(RENDER_SCRIPT_VIEW_ID)) { // render the script writeScript(event); eventgetFacesContext()responseComplete(); } } static final String RENDER_SCRIPT_VIEW_ID = "SpellCheckTextAreaajaxScript"; private static final String SCRIPT_RESOURCE_NAME = "/com/jsfcompref/components/component/ajaxjs"; private void writeScript(PhaseEvent event) { URL url = getClass()getResource(SCRIPT_RESOURCE_NAME); URLConnection conn = null; InputStream stream = null; BufferedReader bufReader = null; HttpServletResponse response = (HttpServletResponse)event getFacesContext()getExternalContext()getResponse(); OutputStreamWriter outWriter = null; String curLine = null; try { outWriter = new OutputStreamWriter(responsegetOutputStream(), responsegetCharacterEncoding()); conn = urlopenConnection(); connsetUseCaches(false); stream = conngetInputStream(); bufReader = new BufferedReader(new InputStreamReader(stream)); responsesetContentType("text/javascript"); while (null != (curLine = bufReaderreadLine())) { outWriterwrite(curLine+"\n"); } outWriterclose(); } catch (Exception e) { String message = null; message = "Can't load script file:" + urltoExternalForm(); responsesendError(HttpServletResponseSC_BAD_REQUEST, message); } }
The full code for the SpellcheckPhaseListener is included on the Web site for this book; however, the writeScript( ) method deserves special attention This method uses the ClassLoader to load the ajaxjs file and sends it out to the HttpServletResponse, making sure to set the contentType to text/javascript and the status to 200 The call to responseComplete( ) is needed because it tells the Faces lifecycle that the response for this request has been written
11:
Copyright © OnBarcode.com . All rights reserved.