net.bootsfaces.expressions.FindIdRecursiveExpressionResolver Maven / Gradle / Ivy
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 FindIdRecursiveExpressionResolver 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();
}
List c = findIdsRecursively(searchRoot, parameters[0]);
if (null != c) {
result.addAll(c);
}
}
if (result.size() > 0) {
return result;
}
throw new FacesException("Invalid search expression - couldn't find id " + currentId + ". Complete search expression: " + originalExpression);
}
public List findIdsRecursively(UIComponent parent, String id) {
if (null==parent)
return null;
List result = null;
if (id.equals(parent.getId())) {
result = new ArrayList();
result.add(parent);
}
Iterator facetsAndChildren = parent.getFacetsAndChildren();
while (facetsAndChildren.hasNext()) {
UIComponent child = facetsAndChildren.next();
List childresult = findIdsRecursively(child, id);
if (null != childresult && (!childresult.isEmpty())) {
if (null == result) {
result = new ArrayList();
}
result.addAll(childresult);
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy