Skip to main content

Clearing the stale messages from the previous request on client side validation error

While going through a specific use case, I came to know that ADF Faces run time does not auto clear the messages added to the page from the previous request. This indeed is the expected behavior as of now. I'm sure many of you know this already, however thought of posting this for the benefit of developers who has not worked on such scenarios before, like me;).

The side effect of this implementation is that, once you displayed any message to the end user by adding a FeacesMessage to a FacesConetxt from an event handler method and if the next immediadte action from the end user result in anay client side validation error, you may get the previous message and the newly generated validation error in the message window as shown in the following screen shot.


Let me discuss a work around solution for such use cases. Its simple, add a af:clientListener to the UI component to clear the messages by calling ADF Fcaes JavaScript API AdfPage.PAGE.clearMessages(componentId);.
 <af:commandButton text="Save with Clearing Prev Message"   
      id="cb2" actionListener="#{TestBean.saveAction}"  
   partialSubmit="true">  
      <af:clientListener method="clearGlobalMessage" type="click"/>  
 </af:commandButton>  
 </af:form>  
 <af:resource type="javascript">  
  function clearGlobalMessage() {  
       AdfPage.PAGE.clearMessages(null);  
  }  
 </af:resource>  

Download

I'm attaching a very simple example illustrating the above solution. You can download the sample workspace from here.
[Built using Oracle JDeveloper 11.1.2.0.0]

How to run this sample?

Run test.jspx, key in some values in the input field and click save button. You may see information message. If you click save button again, validation error message alone appears.The previous INFO message is cleared using javascript method clearGlobalMessage()

Please note that, the above case will be addressed in future releases in a much better way. In fact there is an enhancement request for the same, be happy :)

Comments

Anonymous said…
Excellent.
Hi,

Is there a way to customize the default validation popup?
Like, remove the hyperlink for the mandatory fields, etc.?

Thanks!

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…