Here is an implementation of a reset button under similar circumstances:
<ice:commandButton actionListener="#{visitor.user.resetFields}"
immediate="true" />
resetFields method:
Code:
public void resetFields(ActionEvent ae) {
UIComponent base = ae.getComponent();
UIComponent parentForm = base.getParent();
while (!(parentForm instanceof HtmlForm)) {
parentForm = parentForm.getParent();
}
clearSingleField(parentForm, "firstName");
clearSingleField(parentForm, "lastName");
clearSingleField(parentForm, "email");
}
And the clearSingleField method:
Code:
private void clearSingleField(UIComponent parent, String id) {
try {
UIInput toClear = (UIInput)parent.findComponent(id);
toClear.setSubmittedValue("");
}catch (Exception ignored) {
/* Intentionally ignored - if this fails the one value won't be cleared */
}
}