Skip to content

Instantly share code, notes, and snippets.

@Chavao
Created October 3, 2012 20:54
Show Gist options
  • Save Chavao/3829774 to your computer and use it in GitHub Desktop.
Save Chavao/3829774 to your computer and use it in GitHub Desktop.
package com.silos.jsf.util;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
/**
*
* @author Chavão <[email protected]>
*/
public class Form {
public void clearFields(String formId) {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
this.clearFields(viewRoot.findComponent(formId).getChildren());
}
private void clearFields(List<UIComponent> elements) {
for(UIComponent element : elements) {
try {
((UIInput) element).resetValue();
} catch (Exception e) {
this.clearFields(element.getChildren());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment