Search in sources :

Example 1 with SearchExpressionHint

use of org.primefaces.expression.SearchExpressionHint in project primefaces by primefaces.

the class RowExpressionResolver method resolveClientIds.

@Override
public String resolveClientIds(FacesContext context, UIComponent source, UIComponent last, String expression, Set<SearchExpressionHint> hints) {
    int row = validate(context, source, last, expression);
    UIData data = (UIData) last;
    char separatorChar = UINamingContainer.getSeparatorChar(context);
    StringBuilder clientIds = new StringBuilder();
    for (UIComponent column : data.getChildren()) {
        // handle dynamic columns
        if (column instanceof Columns) {
            List<DynamicColumn> dynamicColumns = ((Columns) column).getDynamicColumns();
            for (int i = 0; i < dynamicColumns.size(); i++) {
                DynamicColumn dynamicColumn = dynamicColumns.get(i);
                for (UIComponent comp : column.getChildren()) {
                    if (clientIds.length() > 0) {
                        clientIds.append(" ");
                    }
                    clientIds.append(data.getClientId(context));
                    clientIds.append(separatorChar);
                    clientIds.append(row);
                    clientIds.append(separatorChar);
                    clientIds.append(dynamicColumn.getId());
                    clientIds.append(separatorChar);
                    clientIds.append(i);
                    clientIds.append(separatorChar);
                    clientIds.append(comp.getId());
                }
            }
        } else if (column instanceof UIColumn) {
            for (UIComponent cell : column.getChildren()) {
                if (clientIds.length() > 0) {
                    clientIds.append(" ");
                }
                clientIds.append(data.getClientId(context));
                clientIds.append(separatorChar);
                clientIds.append(row);
                clientIds.append(separatorChar);
                clientIds.append(cell.getId());
            }
        }
    }
    return clientIds.toString();
}
Also used : UIColumn(javax.faces.component.UIColumn) UIComponent(javax.faces.component.UIComponent) Columns(org.primefaces.component.columns.Columns) DynamicColumn(org.primefaces.component.api.DynamicColumn) SearchExpressionHint(org.primefaces.expression.SearchExpressionHint) UIData(javax.faces.component.UIData)

Example 2 with SearchExpressionHint

use of org.primefaces.expression.SearchExpressionHint in project primefaces by primefaces.

the class UITable method updateFilterByWithGlobalFilter.

default void updateFilterByWithGlobalFilter(FacesContext context, Map<String, FilterMeta> filterBy, AtomicBoolean filtered) {
    // #globalFilter sets the default value, which will be assigned to the "globalFilter" input
    String globalFilterDefaultValue = getGlobalFilter();
    // if #globalFilter is set, the "globalFilter" is mandatory
    Set<SearchExpressionHint> hint = LangUtils.isBlank(globalFilterDefaultValue) ? SearchExpressionUtils.SET_IGNORE_NO_RESULT : SearchExpressionUtils.SET_NONE;
    UIComponent globalFilterComponent = SearchExpressionFacade.resolveComponent(context, (UIComponent) this, GLOBAL_FILTER_COMPONENT_ID, hint);
    if (globalFilterComponent != null) {
        if (globalFilterComponent instanceof ValueHolder) {
            ((ValueHolder) globalFilterComponent).setValue(globalFilterDefaultValue);
        }
        FilterMeta globalFilterBy = FilterMeta.of(globalFilterDefaultValue, getGlobalFilterFunction());
        filterBy.put(globalFilterBy.getColumnKey(), globalFilterBy);
        filtered.set(filtered.get() || globalFilterBy.isActive());
    }
}
Also used : FilterMeta(org.primefaces.model.FilterMeta) SearchExpressionHint(org.primefaces.expression.SearchExpressionHint) UIComponent(javax.faces.component.UIComponent) ValueHolder(javax.faces.component.ValueHolder)

Example 3 with SearchExpressionHint

use of org.primefaces.expression.SearchExpressionHint in project primefaces by primefaces.

the class PreviousExpressionResolver method resolveComponent.

@Override
public UIComponent resolveComponent(FacesContext context, UIComponent source, UIComponent last, String expression, Set<SearchExpressionHint> hints) {
    UIComponent parent = last.getParent();
    if (parent.getChildCount() > 1) {
        List<UIComponent> children = parent.getChildren();
        int index = children.indexOf(last);
        if (index > 0) {
            int nextIndex = -1;
            do {
                index--;
                String className = children.get(index).getClass().getName();
                if (!className.contains("UIInstructions") && !className.contains("UILeaf")) {
                    nextIndex = index;
                }
            } while (nextIndex == -1 && index > 0);
            if (nextIndex != -1) {
                return children.get(nextIndex);
            }
        }
    }
    return null;
}
Also used : UIComponent(javax.faces.component.UIComponent) SearchExpressionHint(org.primefaces.expression.SearchExpressionHint)

Example 4 with SearchExpressionHint

use of org.primefaces.expression.SearchExpressionHint in project primefaces by primefaces.

the class ChildExpressionResolver method resolveComponent.

@Override
public UIComponent resolveComponent(FacesContext context, UIComponent source, UIComponent last, String expression, Set<SearchExpressionHint> hints) {
    Matcher matcher = PATTERN.matcher(expression);
    if (matcher.matches()) {
        int childNumber = Integer.parseInt(matcher.group(1));
        if (childNumber + 1 > last.getChildCount()) {
            throw new FacesException("Component with clientId \"" + last.getClientId(context) + "\" has fewer children as \"" + childNumber + "\". Expression: \"" + expression + "\"");
        }
        List<UIComponent> list = last.getChildren();
        int count = 0;
        for (int i = 0; i < last.getChildCount(); i++) {
            String className = list.get(i).getClass().getName();
            if (!className.contains("UIInstructions") && !className.contains("UILeaf")) {
                count++;
            }
            if (count == childNumber + 1) {
                return last.getChildren().get(childNumber);
            }
        }
        if (count < childNumber) {
            throw new FacesException("Component with clientId \"" + last.getClientId(context) + "\" has fewer children as \"" + childNumber + "\". Expression: \"" + expression + "\"");
        }
    } else {
        throw new FacesException("Expression does not match following pattern @child(n). Expression: \"" + expression + "\"");
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) UIComponent(javax.faces.component.UIComponent) SearchExpressionHint(org.primefaces.expression.SearchExpressionHint) FacesException(javax.faces.FacesException)

Example 5 with SearchExpressionHint

use of org.primefaces.expression.SearchExpressionHint in project primefaces by primefaces.

the class NextExpressionResolver method resolveComponent.

@Override
public UIComponent resolveComponent(FacesContext context, UIComponent source, UIComponent last, String expression, Set<SearchExpressionHint> hints) {
    UIComponent parent = last.getParent();
    if (parent.getChildCount() > 1) {
        List<UIComponent> children = parent.getChildren();
        int index = children.indexOf(last);
        if (index < parent.getChildCount() - 1) {
            int nextIndex = -1;
            do {
                index++;
                String className = children.get(index).getClass().getName();
                if (!className.contains("UIInstructions") && !className.contains("UILeaf")) {
                    nextIndex = index;
                }
            } while (nextIndex == -1 && index < parent.getChildCount() - 1);
            if (nextIndex != -1) {
                return children.get(nextIndex);
            }
        }
    }
    return null;
}
Also used : UIComponent(javax.faces.component.UIComponent) SearchExpressionHint(org.primefaces.expression.SearchExpressionHint)

Aggregations

UIComponent (javax.faces.component.UIComponent)5 SearchExpressionHint (org.primefaces.expression.SearchExpressionHint)5 Matcher (java.util.regex.Matcher)1 FacesException (javax.faces.FacesException)1 UIColumn (javax.faces.component.UIColumn)1 UIData (javax.faces.component.UIData)1 ValueHolder (javax.faces.component.ValueHolder)1 DynamicColumn (org.primefaces.component.api.DynamicColumn)1 Columns (org.primefaces.component.columns.Columns)1 FilterMeta (org.primefaces.model.FilterMeta)1