code: public static UIViewRoot getViewRoot(FaceletContext ctx, UIComponent parent)
      {
          UIComponent c = parent;
          do
          {
              if (c instanceof UIViewRoot)
              {
                  return (UIViewRoot) c;
              }
              else
              {
                  c = c.getParent();
              }
          } while (c != null);
  
          UIViewRoot root = ctx.getFacesContext().getViewRoot();
          if (root == null)
          {
              root = FaceletCompositionContext.getCurrentInstance(ctx).getViewRoot(ctx.getFacesContext());
          }
          return root;
      }
docs: Tries to walk up the parent to find the UIViewRoot, if not found, then go to FaceletContext's FacesContext for
  the view root.
  
  @param ctx
  FaceletContext
  @param parent
  UIComponent to search from
  @return UIViewRoot instance for this evaluation