As far as JSF goes, the most straightforward way to get the list of ids of the children of a component is with the UIComponent#getChildren()
and then iterating on the returned list to perform the reset:
HtmlPanelGrid yourDiv = facesContext.getViewRoot().findComponent("theDivId");//facesContext is an instance of FacesContext
List<UIComponent> children = yourDiv.getChildren();
for(UIComponent child: children){
if(child instanceof UIInput){ //resetValue is applicable only to input comps.
((UIInput)child).resetValue();
}
}
A more sweeping way to reset the values on an entire page is to call the same method on the UIViewRoot
instance associated with that page as in:
FacesContext ctxt = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = ctxt.getViewRoot();
viewRoot.resetValues(ctxt,listOfIds);
Where listOfIds
refers to a Collection<String>
of clientIds belonging to components you want to perform a reset on. Obviously, this requires you to have the component ids beforehand.
JSF 2.2 has introduced the <f:resetValues/>
tag (and resetValues
attribute on the <f:ajax/>
tag) to solve this specific problem