X

The blog for hints & tips about Oracle Application Development Framework and Mobile Application Framework

Using JavaScript to clear validation error messages

Frank Nimphius
Master Principal Product Manager

ADF Faces provides client validation for component
constraints like required fields. If input fields fail validation, then form
data is not submitted to the server and instead an error message is displayed
for the fields causing the error.

The error messages are displayed until the user corrects
the input field values and re-submits the form, which could be irritating to
users. To get rid of error messages of a failed form submit, application
developers can use JavaScript as shown below

<af:resource
type="javascript">
function
clearMessagesForComponent(evt){
AdfPage.PAGE.clearAllMessages();
evt.cancel();
}

</af:resource>

The JavaScript client function is called from the focus
event of a client listener added to the input fields in a form

<af:panelFormLayout
id="pfl1">
<af:inputText
value="#{bindings.EmployeeId.inputValue}" ...>
...
<af:clientListener
method="clearMessagesForComponent"
type="focus"/>
</af:inputText>
<af:inputText
value="#{bindings.FirstName.inputValue}" ... >
...
<af:clientListener
method="clearMessagesForComponent"
type="focus"/>
</af:inputText>
...

</af:panelFormLayout>

Note: The AdfPage.js class provides APIs to access
the component messages and the changed components in list objects to
individually handle component error message instead of clearing them all.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.