/
ChildExpressionResolver.java
33 lines (30 loc) · 1.24 KB
/
ChildExpressionResolver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package net.bootsfaces.expressions;
import java.util.ArrayList;
import java.util.List;
import jakarta.faces.FacesException;
import jakarta.faces.component.UIComponent;
public class ChildExpressionResolver implements AbstractExpressionResolver {
public List<UIComponent> resolve(UIComponent component, List<UIComponent> parentComponents, String currentId,
String originalExpression, String[] parameters) {
if (null==parameters || parameters.length!=1) {
throw new FacesException("The @child search expression required a numerical parameter! " + originalExpression);
}
try {
int index = new Integer(parameters[0]).intValue();
List<UIComponent> result = new ArrayList<UIComponent>();
for (UIComponent parent : parentComponents) {
result.add(parent.getChildren().get(index));
}
if (result.size() > 0) {
return result;
}
throw new FacesException("Error processing the @child search expression. " + originalExpression);
}
catch (NumberFormatException nfe) {
throw new FacesException("The @child search expression required a numerical parameter! " + originalExpression);
}
catch (ArrayIndexOutOfBoundsException nfe) {
throw new FacesException("The component doesn't have so many children! " + originalExpression);
}
}
}