Пример #1
0
 static Renderer getRenderer(final FacesContext context, final UIComponent component) {
   final String rendererType = component.getRendererType();
   if (rendererType == null) {
     return null;
   }
   final RenderKit renderKit = RenderKitUtil.getRenderKit(context);
   return renderKit.getRenderer(component.getFamily(), rendererType);
 }
Пример #2
0
  public static String getWidgetVar(String id) {
    UIComponent component = findComponent(FacesContext.getCurrentInstance().getViewRoot(), id);
    Renderer renderer =
        FacesContext.getCurrentInstance()
            .getRenderKit()
            .getRenderer(component.getFamily(), component.getRendererType());

    if (component == null) throw new FacesException("Cannot find component " + id + " in view.");
    else if (!(renderer instanceof CoreRenderer))
      throw new FacesException("Component with id " + id + " is not derived from CoreRenderer.");

    return ((CoreRenderer) renderer).resolveWidgetVar(component);
  }
 private static UIComponent findLabelFor(UIComponent root, String clientId) {
   for (UIComponent c : (List<UIComponent>) root.getChildren()) {
     if ("javax.faces.Label".equals(c.getRendererType())) {
       String labelFor = (String) c.getAttributes().get("for");
       if (clientId.equals(labelFor) || clientId.endsWith(":" + labelFor)) {
         return c;
       }
     }
     if (c.getChildCount() > 0) {
       // look for the right label recursively
       UIComponent label = findLabelFor(c, clientId);
       if (label != null) {
         return label;
       }
     }
   }
   return null;
 }