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

The following examples show how to use javax.faces.component.UIComponent#getClass() . 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: FormExpressionResolver.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
public List<UIComponent> resolve(UIComponent component, List<UIComponent> parentComponents, String currentId,
			String originalExpression, String[] parameters) {

		List<UIComponent> result = new ArrayList<UIComponent>();
//		for (UIComponent parent : parentComponents) {
			UIComponent c = component;

			while (c != null && c.getClass() != UIViewRoot.class) {
				if (UIForm.class.isAssignableFrom(c.getClass())) {
					result.add(c);
					break;
				}
				c = c.getParent();
			}
//		}
		if (result.size() > 0) {
			return result;
		}
		throw new FacesException("Invalid search expression - the component isn't inside a form " + originalExpression);

	}
 
Example 2
Source File: AddResourcesListener.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
private void addResourceIfNecessary(UIViewRoot root, FacesContext context, UIComponent output, Class<?> clazz) {
	for (UIComponent c : root.getComponentResources(context, "head")) {
		if (c.getClass() == clazz) {
			LOGGER.log(Level.FINER, "by addResourceIfNecessary - find existing class {0}", clazz);

			// remove old
			root.removeComponentResource(context, c, "head");

			// add new
			root.addComponentResource(context, output, "head");
			return;
		}
	}
	// resource not found yet, so add it now
	root.addComponentResource(context, output, "head");
}
 
Example 3
Source File: FormOrThisExpressionResolver.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
public List<UIComponent> resolve(UIComponent component, List<UIComponent> parentComponents, String currentId,
		String originalExpression, String[] parameters) {
	
	
	List<UIComponent> result = new ArrayList<UIComponent>();
	boolean isButton = component instanceof CommandButton || component instanceof NavCommandLink;
	isButton |= component instanceof Poll;
	if (!isButton) {
		result.add(component);
		return result;
	}

	UIComponent c = component;

	while (c != null && c.getClass() != UIViewRoot.class) {
		if (UIForm.class.isAssignableFrom(c.getClass())) {
			result.add(c);
			break;
		}
		c = c.getParent();
	}
	if (result.size() > 0) {
		return result;
	}

	c = component;

	while (c != null && c.getClass() != UIViewRoot.class) {
		if (NamingContainer.class.isAssignableFrom(c.getClass())) {
			result.add(c);
			break;
		}
		c = c.getParent();
	}
	if (result.size() > 0) {
		return result;
	}
	else {
		result.add(component);
		return result;
	}
}