All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.bootsfaces.expressions.FindIdExpressionResolver Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package net.bootsfaces.expressions;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.faces.FacesException;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;

public class FindIdExpressionResolver implements AbstractExpressionResolver {
	public List resolve(UIComponent component, List parentComponents, String currentId,
			String originalExpression, String[] parameters) {

		List result = new ArrayList();
		for (UIComponent parent : parentComponents) {
			UIComponent searchRoot = parent;
			while ((!(searchRoot instanceof UIViewRoot)) && (!(searchRoot instanceof NamingContainer))) {
				searchRoot = searchRoot.getParent();
			}
				
			UIComponent c = findId(searchRoot, parameters[0]);
			if (null != c) {
				result.add(c);
			}
		}
		if (result.size() > 0) {
			return result;
		}

		throw new FacesException("Invalid search expression - couldn't find id " + currentId + ". Complete search expression: " + originalExpression);
	}

	public UIComponent findId(UIComponent parent, String id) {
		if (null==parent)
			return null;
		if (id.equals(parent.getId())) {
			return parent;
		}
		Iterator facetsAndChildren = parent.getFacetsAndChildren();
		while (facetsAndChildren.hasNext()) {
			UIComponent child = facetsAndChildren.next();
			if (id.equals(child.getId())) {
				return child;
			}
		}
		return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy