Java Code Examples for javax.faces.component.UIComponent#setId()

The following examples show how to use javax.faces.component.UIComponent#setId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataTableRenderer.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
private void resetClientIdCacheRecursively(UIComponent c) {
	String id = c.getId();
	if (null != id) {
		c.setId(id); // this strange operation clears the cache of the clientId
	}
	Iterator<UIComponent> children = c.getFacetsAndChildren();
	if (children != null) {
		while (children.hasNext()) {
			UIComponent kid = children.next();
			resetClientIdCacheRecursively(kid);
		}
	}
}
 
Example 2
Source File: TabRepeat.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
private void removeChildState(FacesContext faces, UIComponent c) {
	String id = c.getId();
	c.setId(id);

	Iterator itr = c.getFacetsAndChildren();
	while (itr.hasNext()) {
		removeChildState(faces, (UIComponent) itr.next());
	}
	if (this.childState != null) {
		this.childState.remove(c.getClientId(faces));
	}
}
 
Example 3
Source File: TabRepeat.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
private void restoreChildState(FacesContext faces, UIComponent c) {
	// reset id
	String id = c.getId();
	c.setId(id);

	// hack
	if (c instanceof EditableValueHolder) {
		EditableValueHolder evh = (EditableValueHolder) c;
		String clientId = c.getClientId(faces);
		SavedState ss = this.getChildState().get(clientId);
		if (ss != null) {
			ss.apply(evh);
		} else {
			String childId = clientId.substring(initialClientId.length() + 1);
			childId = childId.substring(childId.indexOf(getSeparatorChar(faces)) + 1);
			childId = initialClientId + getSeparatorChar(faces) + childId;
			if (initialChildState.containsKey(childId)) {
				SavedState initialState = initialChildState.get(childId);
				initialState.apply(evh);
			} else {
				NullState.apply(evh);
			}
		}
	}

	// continue hack
	Iterator itr = c.getFacetsAndChildren();
	while (itr.hasNext()) {
		restoreChildState(faces, (UIComponent) itr.next());
	}
}
 
Example 4
Source File: TabRepeat.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
private void resetClientIds(UIComponent component) {
	Iterator<UIComponent> iterator = component.getFacetsAndChildren();
	while (iterator.hasNext()) {
		UIComponent child = iterator.next();
		resetClientIds(child);
		child.setId(child.getId());
	}
}
 
Example 5
Source File: Node.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
/**
   * @param cl
   * @return
   * @throws ClassNotFoundException
   * @throws IllegalAccessException
   * @throws InstantiationException
   */
  public UIComponent restoreInstance(ClassLoader cl)
          throws ClassNotFoundException, IllegalAccessException,
          InstantiationException {
      Class<?> c = cl.loadClass(_className);
UIComponent comp = (UIComponent) c.newInstance();
comp.setId(_id);
      return comp;
  }
 
Example 6
Source File: UIDataRepeater.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void processDecodes(FacesContext context) {
    int first = getFirst();
    int rows = getRows();
    int last;

    if (rows == 0) {
        last = getRowCount();
    } else {
        last = first + rows;
    }

    for (int rowIndex = first; rowIndex < last; rowIndex++) {
        setRowIndex(rowIndex);
        if (isRowAvailable()) {
            for (Iterator it = getChildren().iterator(); it.hasNext();) {
                UIComponent child = (UIComponent) it.next();
                // For some reason its necessary to touch Id property,
                // otherwise the child control will not call getClientId
                // on
                // parent (NamingContainer)
                child.setId(child.getId());
                if (!child.isRendered()) {
                    continue;
                }
                child.processDecodes(context);
            }
        }
    }

    setRowIndex(-1);

    super.processDecodes(context);
}
 
Example 7
Source File: UIDataRepeater.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void processUpdates(FacesContext context) {
    int first = getFirst();
    int rows = getRows();
    int last;
    if (rows == 0) {
        last = getRowCount();
    } else {
        last = first + rows;
    }
    for (int rowIndex = first; rowIndex < last; rowIndex++) {
        setRowIndex(rowIndex);
        if (isRowAvailable()) {
            for (Iterator it = getChildren().iterator(); it.hasNext();) {
                UIComponent child = (UIComponent) it.next();
                // For some reason its necessary to touch Id property,
                // otherwise the child control will not call getClientId
                // on
                // parent (NamingContainer)
                child.setId(child.getId());

                if (!child.isRendered()) {
                    continue;
                }
                child.processUpdates(context);
            }
        }
    }

    setRowIndex(-1);

    super.processUpdates(context);
}
 
Example 8
Source File: UIDataRepeater.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void processValidators(FacesContext context) {
    int first = getFirst();
    int rows = getRows();
    int last;
    if (rows == 0) {
        last = getRowCount();
    } else {
        last = first + rows;
    }
    for (int rowIndex = first; rowIndex < last; rowIndex++) {
        setRowIndex(rowIndex);
        if (isRowAvailable()) {
            for (Iterator it = getChildren().iterator(); it.hasNext();) {
                UIComponent child = (UIComponent) it.next();
                // For some reason its necessary to touch Id property,
                // otherwise the child control will not call getClientId
                // on
                // parent (NamingContainer)
                child.setId(child.getId());
                if (!child.isRendered()) {
                    continue;
                }
                child.processValidators(context);
            }
        }
    }

    setRowIndex(-1);

    super.processValidators(context);
}
 
Example 9
Source File: UIDataRepeaterRenderer.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {

    UIDataRepeater dataRepeater = (UIDataRepeater) component;

    int first = dataRepeater.getFirst();
    int rows = dataRepeater.getRows();
    int rowCount = dataRepeater.getRowCount();

    if (rows <= 0) {
        rows = rowCount - first;
    }

    int last = first + rows;

    if (last > rowCount) {
        last = rowCount;
    }

    for (int i = first; i < last; i++) {
        dataRepeater.setRowIndex(i);
        if (dataRepeater.isRowAvailable()) {
            if (dataRepeater.getChildCount() > 0) {
                for (Iterator it = dataRepeater.getChildren().iterator(); it.hasNext();) {
                    UIComponent child = (UIComponent) it.next();
                    // For some reason its necessary to touch Id property,
                    // otherwise
                    // the child control will not call getClientId on parent
                    // (NamingContainer)
                    child.setId(child.getId());
                    encodeRecursive(context, child);
                }
            }

        }
    }
}
 
Example 10
Source File: XspRenderUtil.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
/**
 * @param root
 * @param p
 * @param instance
 * @throws Exception
 */
public static void resetContainerChild(UIViewRoot root, UIComponent p,
        UIComponent instance) throws Exception{
    
    // clear out any changes caused by the previous rendering/encode
    Map<String, Object> rootAttrs = TypedUtil.getAttributes(root);
    rootAttrs.put("dojoParseOnLoad", false);
    rootAttrs.put("dojoTheme", false);
    rootAttrs.put("loadXspClientDojoUI",false);
    if( ! UIViewRoot.class.equals(root.getClass()) ){
        // UIViewRootEx and the other subclass have this clear.. method
        // root.clearEncodeResources();
        Method mtd = root.getClass().getMethod("clearEncodeResources", new Class[0]);
        if( null != mtd ){
            mtd.invoke(root, new Object[0]);
        }
        //root._lastUniqueId = 100;
        Class<?> viewRootClass = Class.forName("com.ibm.xsp.component.UIViewRootEx");
        Field lastIdField = viewRootClass.getDeclaredField("_lastUniqueId");
        lastIdField.setAccessible(true); // change private to public
        try{
            lastIdField.set(root, 100);
        }finally{
            lastIdField.setAccessible(false);
        }
    }
    
    UIComponent rootChild = TypedUtil.getChildren(root).get(0);
    if( !(rootChild instanceof UIForm) && rootChild.getClass().getName().contains("ScriptCollector") ){
        // rootChild is a UIScriptCollector
        UIComponent scriptCollector = rootChild;
        // scriptCollector.reset();
        Method resetMethod = scriptCollector.getClass().getMethod("reset");
        resetMethod.invoke(scriptCollector);
    }
    
    // remove any previous child of the container
    List<UIComponent> kids = TypedUtil.getChildren(p);
    kids.clear();
    kids.add(instance);
    
    // ensure the child has an auto-generated ID.
    if (instance.getId() == null){ 
        instance.setId(root.createUniqueId());
    }
    
    FacesUtil.checkComponentIds(root, p);
}