This content has been marked as final.
Show 2 replies
-
1. Re: Solution optimization to the "Local values reset sad story"
akaine Feb 7, 2011 9:35 PM (in response to akaine)Partially solved with:
public static void resetComponent(UIComponent c){ if(c instanceof UIInput){ UIInput uiInput = (UIInput)c; uiInput.setValue(null); uiInput.setSubmittedValue(null); } Iterator<UIComponent> children = c.getFacetsAndChildren(); while(children.hasNext()){ resetComponent(children.next()); } }
where the initial parameter is the form in question component.
-
2. Re: Solution optimization to the "Local values reset sad story"
akaine Oct 1, 2011 10:33 PM (in response to akaine)I know it's a necromancy, still I'd like to share the final solition I made several days after the last post since many people keep asking "what the heck":
import java.util.Iterator; import javax.faces.component.UIComponent; import javax.faces.component.UIInput; import javax.faces.context.FacesContext; public class UtilsJSF{ private static UtilsJSF util; private UtilsJSF(){} public static UtilsJSF getInstance(){ return util == null ? new UtilsJSF() : util; } /** * Resets all UIInput based elements values contained inside the form * * @param context current instance of the FacesContext * @param componentId id of the form to clean * @see UIInput */ public static void resetFormComponent(FacesContext context, String componentId){ UIComponent form = findComponent(context.getViewRoot(),componentId); resetComponent(form); } public static void resetComponent(FacesContext context, String componentId){ UIInput component = (UIInput)findComponent(context.getViewRoot(),componentId); component.setValue(null); component.setSubmittedValue(null); } private static UIComponent findComponent(UIComponent c, String id){ if(id.equals(c.getId())){ return c; } Iterator<UIComponent> kids = c.getFacetsAndChildren(); while(kids.hasNext()){ UIComponent found = findComponent(kids.next(), id); if(found != null){ return found; } } return null; } private static void resetComponent(UIComponent c){ if(c instanceof UIInput){ UIInput uiInput = (UIInput)c; uiInput.setValue(null); uiInput.setSubmittedValue(null); } Iterator<UIComponent> children = c.getFacetsAndChildren(); while(children.hasNext()){ resetComponent(children.next()); } } }
Hope this helps