Tuesday, December 14, 2010

How to reset a UI component and all of its childs?

    private void resetUnbound(UIComponent component) {
       System.out.println("==resetUnbound()==");
     
       FacesContext context = FacesContext.getCurrentInstance();
       java.util.Stack<UIComponent> stack = new java.util.Stack<UIComponent>();
       stack.add(component);
       while (!stack.isEmpty())
       {
         UIComponent target = stack.pop();
         System.out.println("target.getClientId(context): " + target.getClientId(context));
         if (target instanceof UIXEditableValue) {
             ValueExpression ve = ((UIXEditableValue) target).getValueExpression("value");
             // if the component has a value binding, setting the value will override
             // the EL.
             if (ve == null) {
                 ((UIXEditableValue) target).setValue("");
             }
             ((UIXEditableValue) target).setSubmittedValue(null);
         }
         for (java.util.Iterator<UIComponent> ci = target.getFacetsAndChildren(); ci.hasNext();) {
              stack.push(ci.next());
         }
       }
    }

No comments:

Post a Comment