An Oracle JDeveloper TechNote
This document was developed using Oracle9i JDeveloper release 9.0.3. If you are using JDeveloper 9.0.2 the solution is the same, but you will find some differences in the screenshots provided.
Client side validation allows immediate response to a user interacting within an HTML form. For example, the response could display an alert when a business rule is violated or correct data if an entry does not have the desired format. Client side validation is not meant to replace server side enforcement of business and format rules. It should be thought of as a convenience for the end user to avoid waiting for a server to respond just to find out whether the submitted data was correct.
Creating a new BC4J JSP Browse&Edit Form with JDeveloper 9.0.3, adds the component file,
DataEditComponent.jsp, to the project. This component file handles the rendering and data binding of the HTML form fields in the application. Because the
DataEditComponent.jsp file is designed for reuse with many JSP pages requiring data input forms, the rendering code in the JSP page is generic. By default the following code is generated by JDeveloper when creating
<jbo:AttributeIterate id="def" datasource="dsEdit">
<td title="<jbo:ShowHint hintname='TOOLTIP'/>" align="right"><jbo:ShowHint hintname="LABEL" /></td>
<td title="<jbo:ShowHint hintname='TOOLTIP'/>"><jbo: InputRender datasource="dsEdit" formname="<%=formName%>"/></td>
The actual field rendering is performed by the BC4J JSP
InputRender tag and will layout all fields as text fields.
The following HTML form is created by the
DataEditComponent.jsp referenced from
PeopleView1_Edit.jsp. When using the BC4J JSP wizard to create a default set of pages, then the name of the edit page always contains the name of the underlying view object upon which it operates. Throughout this document name of the view object instance, that the edit form is build upon, is named
PeopleView1_edit.jsp contains all JSP code related to building the page, except for rendering the HTML form and the form fields. This information is included to the page during runtime by the BC4J JSP
<jbo:DataEdit datasource="ds" enctype=""/>
The image below shows a data entry form rendered by the
DataEditComponent.jsp component contained in the
Because all attributes are rendered by the same
password field. If the same strings are used, then an alert shall be displayed informing the user that the entered data is not valid.
InputRenderer tag uses a Java class on the server to define the HTML field including data read from the associated attribute in the view object. All default BC4J HTML renderers are stored in the
oracle.jdeveloper.html package and can be subclassed from there. And this is how the client side validation is added to the view object or entity object in the following example.
onSelect. All these events, or at least some of them, must be rendered by the BC4J HTML renderer to perform client side validation.
In this howto document, the
clientSideValidationrenderer.java file was created, representing a subclass of the
oracle.jdeveloper.html.TextField renderer. The
clientSideValidationrenderer.java contains additional code for the following tasks:
<%attribute_name%>, by the current value of the attribute specified
The following two methods are contained in
clientSideValidationrenderer.java as either an overwriting method or new method.
renderToString() method in the custom HTML renderer overwrites the
renderToString() method of the
<%attribute_name%> placeholders , then the string gets parsed separately using the
parseArguments() method, replacing the placeholders by the actual attribute value .
parseArguments() method replaces placeholders in the command string by the value of the attribute they define. The placeholder
oracle.jdeveloper.html package rather than the TextField class.
password field or the
username field, providing the default username and password pair to the variables. The fourth function is called to compare both strings, displaying an alert if they are the same.
PeopleView1_Edit.jsp, which would have been an option too, but instead is stored in a file
The custom HTML renderer
clientSideValidationRenderer needs to be registered with a view object or entity object attribute to be used during runtime instead of the default item renderer.
Username attribute in the
People entity object. The placeholder
initializeUsername Password() method sets the values of the
password page variable, so that when the user clicks into the
Username text field, the current attribute values of the fields to compare are known. Similar for the password field:
howto.js source file into the
PeopleView1_Edit.jsp page. Note that surrounding
Important: For the custom HTML renderer to work, it is necessary to add the location of the custom HTML renderer class as an additional path in the JSP project. Changes to a project always take effect after recompiling the project.
password field values are the same.
onFocus="initializeUsernamePassword('ddursley','dudley');" VALUE="ddursley" TYPE="TEXT" MAXLENGTH="15" NAME="Username" SIZE="20" CLASS="clsUsername"
DataEditComponent.jsp, a custom BC4J HTML renderer needs to be written and registered with the view or entity object attributes. Client side validation is for user convenience and does not take away the responsibility of enforcing business rules on the middle tier.
Recommended additional reading: HOWTO: Use BC4J HTML Field Renderersfalse ,,,,,,,,,,,,,,,