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");
}

2 comments:
Thanks very much - worked for me in 10.1.3.4.0.
Don
Can you please explain what dc refers here?
Thanks
Post a Comment