0 Replies Latest reply on Jul 29, 2008 12:35 PM by Robert Gallas

    Altering property of component in ComponentTree

    Robert Gallas Newbie

      Hi,

      I'm facing situation when I need to alter property of component in ComponentTree. Basicly programatically disabling component. I do not want to use component binding in JSF tags.

      I have tried to use for the task PhaseListener, and also View Handler but without any success.

      Here is piece of dummy code.

      Idea is that for compnent with given ID disabled property will be set. Component is found sucessfully but with no effect on rendered UI.

      private void disableButton() {
       viewRoot = FacesContext.getCurrentInstance().getViewRoot();
       if (viewRoot != null)
       //printComponent(viewRoot);
       traverseAndPrintComponent(viewRoot);
       }
      
       private void traverseAndPrintComponent(UIComponent component) {
       if (component.getChildCount() == 0) {
       printComponent(component);
       } else {
       printComponent(component);
       List<UIComponent> components = component.getChildren();
       for (UIComponent comp:components) {
       traverseAndPrintComponent(comp);
       }
       }
       }
      
       private void printComponent(UIComponent component) {
       println("Component.Id: " + component.getId());
       println("Component.Family: " + component.getFamily());
       println("Component.Class: " + component.getClass());
       println("Component.ChildCount: " + component.getChildCount());
       if (component.getId() != null && component.getId().equals("button")) {
       println("Button component found ... disabling ...");
       ((HtmlAjaxCommandButton)component).setDisabled(true);
       }
       println("-----------------------------------------------");
       }


      Any idea how implement functionality?

      Thanks a lot.
      Robert