Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Put Some Ajax4JSF Magic into Data Validation : Page 3

Apply an open source framework that gives you the functionality of AJAX and the best of JSF to validate data entries dynamically on the server side.


advertisement
Preparing for Input

Now you can create an input form using JSF components. Begin by adding a Panel Grid component to the input.jsp page from the JSF HTML component library. Click Next in the Create PanelGrid Wizard. Select Create empty panel grid and specify 2 for the number of columns in the PanelGrid Options frame, and then click Finish. The components that will be added to the panel grid will be arranged in two columns.

Add an Output Label and Input Text component from the component palette in the panel grid. Similarly, add five more Output Label and Input Text components, add a Command Button component to the panel grid that will be used for submitting the form, and add an Output Text component to the panel grid for displaying a validation message that will indicate whether an ID value is valid (see Figure 3). Also specify values for the output labels and the command button components in the Property Inspector area.




Figure 3. Create a Form: Use the JDeveloper IDE's component palette to add five Output Label and Input Text components, a Command Button component, and an Output Text component to the panel grid.

At this point you need to create a JDBC connection with the Oracle database. To create this connection right-click the Database node in the Connections area, and select New Database Connection. Click Next when the Create Database Connection Wizard opens. Specify a connection name, and select the Connection Type as Oracle JDBC in the Type frame, and click Next.

For this example specify OE for both the username and password in the Authentication frame, and click Next. Then select the default connection settings in the Connection frame, and click Next. Click Test Connection in the Test frame to test the connection, and click Finish. You will see that a connection is added to the Connections area.

Add a resource-ref element to the web.xml file for the Oracle data source, and also add an ajax4jsf filter and filter mapping to web.xml. Be sure to also specify a listener class. The web.xml file is shown in Listing 1.

Next, you want to modify the JSF faces-config.xml configuration file. Add a navigation rule for navigating to the catalog.jsp page if a catalog entry gets created, and for navigating to the error.jsp page:

<?xml version="1.0" encoding="windows-1252"?> <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"> <faces-config xmlns="http://java.sun.com/JSF/Configuration"> <managed-bean> <managed-bean-name>backing_input</managed-bean-name> <managed-bean-class>ajaxjsf.backing.Input</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <!--oracle-jdev-comment:managed-bean-jsp-link:1input.jsp--> </managed-bean> <navigation-rule> <from-view-id>/input.jsp</from-view-id> <navigation-case> <from-outcome>catalog</from-outcome> <to-view-id>/catalog.jsp</to-view-id> </navigation-case> <navigation-case> <from-outcome>error</from-outcome> <to-view-id>/error.jsp</to-view-id> </navigation-case> </navigation-rule> </faces-config>



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap