Pages

Thursday, February 12, 2009

Reset / Clear an ADF page

Sometimes you want to reset or clear the jsf page without leaving and reloading the page. This can be a little tricky, it depends if you are using ADF inputtext items with ADF pagedef bindings or use it values from a backing bean.

First we need to add an button on the page with an actionlistener

<af:commandButton text="Revert Changes" actionListener="#{MainBean.revertCategories}"/>

In this backing bean method we can reset the ADF bindings. Use this code to requery all the iterators in the pagedef.
   
public void revertCategories(ActionEvent actionEvent) {
dc.refreshControl();
DCIteratorBinding iterBind= (DCIteratorBinding)dc.get("queryCategoryFindAllIterator");
iterBind.executeQuery();
iterBind.refresh(DCIteratorBinding.RANGESIZE_UNLIMITED);
}


Resetting inputtext items based on values in a backing bean can be tricky especially when a user has changed an inputtext component. In that case you can try to reset this value from the backing bean, but it may not work because the submittedValue of the uicomponent with the user input is still set. We need to reset the inputtext uicomponent and add partial trigger to it. Here is the code to do this. This method has as input parameter the backing bean binding of a form or an other higher uicomponent. This method will reset all the childern uicomponents who are not disabled.


private void resetValueInputItems(AdfFacesContext adfFacesContext, UIComponent component){
List<UIComponent> items = component.getChildren();
for ( UIComponent item : items ) {

resetValueInputItems(adfFacesContext,item);

if ( item instanceof RichInputText ) {
RichInputText input = (RichInputText)item;
if ( !input.isDisabled() ) {
input.resetValue() ;
adfFacesContext.addPartialTarget(input);
};
} else if ( item instanceof RichInputDate ) {
RichInputDate input = (RichInputDate)item;
if ( !input.isDisabled() ) {
input.resetValue() ;
adfFacesContext.addPartialTarget(input);
};
}
}
}

public void resetForm(ActionEvent actionEvent) {
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
resetValueInputItems(adfFacesContext,vvFormBinding );
testMap.put("TEST", "initial value");
}

11 comments:

  1. Thanks very much - worked for me in 10.1.3.4.0.
    Don

    ReplyDelete
  2. Can you please explain what dc refers here?

    Thanks

    ReplyDelete
  3. What is dc and how to create it?????

    ReplyDelete
  4. Hi,

    you are right that is
    DCBindingContainer dcBindings = ADFUtils.getDCBindingContainer();
    dcBindings.resetInputState();
    dcBindings.refreshControl();

    hope this helps

    ReplyDelete
  5. Why not use BindingContext.getCurrent().getCurrentBindingsEntry() rather than ADFUtils which is not available unless you create it or copy it from somewhere.

    ReplyDelete
  6. vvFormBinding
    how to create this ?

    ReplyDelete
  7. public void TstActionListeners(ActionEvent actionEvent) {
    // Add event code here...
    DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    dcBindings.resetInputState();
    dcBindings.refreshControl();
    DCIteratorBinding iterBind= (DCIteratorBinding)dcBindings.get("GlLvlAccountsS1VO1Iterators");
    iterBind.executeQuery();
    iterBind.refresh(DCIteratorBinding.RANGESIZE_UNLIMITED);
    }

    Caused by: java.sql.SQLException: ORA-01427: single-row subquery returns more than one row

    throw some error.
    can you mail you this examples.

    ReplyDelete
  8. Hi,

    that is the uicomponent around the inputtext items. like a formLayout etc.

    when you lookup the id and retrieve the uicomponent then you have it.
    or use the binding attribute on the formlayout and map this to a managed bean with contains the reset code.

    thanks

    ReplyDelete
  9. Hi,

    I have same problem in mobile ADF(Jdeveloper 11g release 2.4).
    After submitting values, I am getting same vales in text boxes when I again go to same page by navigation.
    In my bean I wrote
    ValueExpression veIter =
    (ValueExpression)AdfmfJavaUtilities.getValueExpression("#{bindings.DemoBeanIterator}",Object.class);
    AmxIteratorBinding iteratorBinding =(AmxIteratorBinding)veIter.getValue(AdfmfJavaUtilities.getAdfELContext());
    iteratorBinding.getIterator().refresh();

    But the page is not getting refreshed.
    I set refresh always to all iterators.

    Any help would be appreciated.

    Thanks..

    ReplyDelete
    Replies
    1. Hi

      maybe you can do something with PPR, change event on the iterator and do some ppr on the component around these fields

      Thanks

      Delete
  10. what happen if i set autoSubmit = true on there components ?

    ReplyDelete