Search in sources :

Example 26 with UIData

use of javax.faces.component.UIData in project primefaces by primefaces.

the class RowExpressionResolver method validate.

protected int validate(FacesContext context, UIComponent source, UIComponent last, String expression) {
    if (!(last instanceof UIData)) {
        throw new FacesException("The last resolved component must be instance of UIData to support @row. Expression: \"" + expression + "\" referenced from \"" + last.getClientId(context) + "\".");
    }
    try {
        Matcher matcher = PATTERN.matcher(expression);
        if (matcher.matches()) {
            int row = Integer.parseInt(matcher.group(1));
            if (row < 0) {
                throw new FacesException("Row number must be greater than 0. Expression: \"" + expression + "\"");
            }
            UIData data = (UIData) last;
            if (data.getRowCount() < row + 1) {
                throw new FacesException("The row count of the target is lesser than the row number. Expression: \"" + expression + "\"");
            }
            return row;
        } else {
            throw new FacesException("Expression does not match following pattern @row(n). Expression: \"" + expression + "\"");
        }
    } catch (Exception e) {
        throw new FacesException("Expression does not match following pattern @row(n). Expression: \"" + expression + "\"", e);
    }
}
Also used : Matcher(java.util.regex.Matcher) FacesException(javax.faces.FacesException) SearchExpressionHint(org.primefaces.expression.SearchExpressionHint) FacesException(javax.faces.FacesException) UIData(javax.faces.component.UIData)

Example 27 with UIData

use of javax.faces.component.UIData in project primefaces by primefaces.

the class UIDataContextCallback method invokeContextCallback.

@Override
public void invokeContextCallback(FacesContext fc, UIComponent component) {
    String[] idTokens = dragId.split(String.valueOf(UINamingContainer.getSeparatorChar(fc)));
    String dataId = idTokens[idTokens.length - 2];
    if (component instanceof UITree) {
        UITree uiTree = (UITree) component;
        uiTree.setRowKey(dataId);
        data = uiTree.getRowNode();
        uiTree.setRowKey(null);
    } else {
        UIData uiData = (UIData) component;
        uiData.setRowIndex(Integer.parseInt(dataId));
        data = uiData.getRowData();
        uiData.setRowIndex(-1);
    }
}
Also used : UITree(org.primefaces.component.api.UITree) UIData(javax.faces.component.UIData)

Example 28 with UIData

use of javax.faces.component.UIData in project primefaces by primefaces.

the class Droppable method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    if (ComponentUtils.isRequestSource(this, context)) {
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
        String clientId = getClientId(context);
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        if ("drop".equals(eventName)) {
            String dragId = params.get(clientId + "_dragId");
            String dropId = params.get(clientId + "_dropId");
            DragDropEvent dndEvent = null;
            String datasourceId = getDatasource();
            if (datasourceId != null) {
                UIData datasource = findDatasource(context, this, datasourceId);
                String[] idTokens = dragId.split(String.valueOf(UINamingContainer.getSeparatorChar(context)));
                int rowIndex = Integer.parseInt(idTokens[idTokens.length - 2]);
                datasource.setRowIndex(rowIndex);
                Object data = datasource.getRowData();
                datasource.setRowIndex(-1);
                dndEvent = new DragDropEvent(this, behaviorEvent.getBehavior(), dragId, dropId, data);
            } else {
                dndEvent = new DragDropEvent(this, behaviorEvent.getBehavior(), dragId, dropId);
            }
            super.queueEvent(dndEvent);
        }
    } else {
        super.queueEvent(event);
    }
}
Also used : DragDropEvent(org.primefaces.event.DragDropEvent) FacesContext(javax.faces.context.FacesContext) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) UIData(javax.faces.component.UIData)

Example 29 with UIData

use of javax.faces.component.UIData in project empire-db by apache.

the class TagEncodingHelper method findRecordComponent.

public Object findRecordComponent() {
    // already present?
    if (this.recordTag != null)
        return this.recordTag.getRecord();
    if (this.uiDataTag != null) {
        // check row available
        if (this.uiDataTag.isRowAvailable())
            return this.uiDataTag.getRowData();
        // row not available (possibly deleted)
        return null;
    }
    // walk upwards the parent component tree and return the first record component found (if any)
    UIComponent parent = component;
    while ((parent = parent.getParent()) != null) {
        if (parent instanceof RecordTag) {
            this.recordTag = (RecordTag) parent;
            return this.recordTag.getRecord();
        }
        if (parent instanceof UIData) {
            this.uiDataTag = (UIData) parent;
            this.insideUIData = true;
            return (this.uiDataTag.isRowAvailable() ? this.uiDataTag.getRowData() : null);
        }
    }
    return null;
}
Also used : RecordTag(org.apache.empire.jsf2.components.RecordTag) UIComponent(javax.faces.component.UIComponent) UIData(javax.faces.component.UIData)

Example 30 with UIData

use of javax.faces.component.UIData in project empire-db by apache.

the class InputControl method getInputComponent.

protected UIInput getInputComponent(UIComponent parent) {
    // default implementation
    int count = parent.getChildCount();
    if (count < 1)
        return null;
    // find the UIInput component (only one allowed here)
    UIInput inp = null;
    for (int i = 0; i < count; i++) {
        // check UIInput
        UIComponent comp = parent.getChildren().get(i);
        if (comp instanceof UIInput) {
            if (inp != null)
                throw new UnexpectedReturnValueException(comp, "comp.getChildren().get(" + String.valueOf(i) + ")");
            inp = (UIInput) comp;
        }
    }
    // No UIInput found
    if (inp == null) {
        // Check whether inside a DataTable (javax.faces.component.UIData)
        for (UIComponent p = parent.getParent(); p != null; p = p.getParent()) {
            // Check whether inside UIData
            if (p instanceof UIData) {
                log.info("Ignore value component for id '{}' inside a DataTable (javax.faces.component.UIData)", parent.getClientId());
                return null;
            }
        }
        // Should not happen!
        throw new UnexpectedReturnValueException(null, "comp.getChildren().get()");
    }
    // found one
    return inp;
}
Also used : UnexpectedReturnValueException(org.apache.empire.exceptions.UnexpectedReturnValueException) UIComponent(javax.faces.component.UIComponent) UIInput(javax.faces.component.UIInput) UIData(javax.faces.component.UIData)

Aggregations

UIData (javax.faces.component.UIData)46 UIComponent (javax.faces.component.UIComponent)6 Tag (com.autentia.tnt.businessobject.Tag)3 Position (com.autentia.tnt.businessobject.Position)2 User (com.autentia.tnt.businessobject.User)2 Paginator (com.liferay.faces.alloy.component.paginator.Paginator)2 SearchExpressionHint (org.primefaces.expression.SearchExpressionHint)2 ActivityFile (com.autentia.tnt.businessobject.ActivityFile)1 CommissioningFile (com.autentia.tnt.businessobject.CommissioningFile)1 CommissioningPaymentData (com.autentia.tnt.businessobject.CommissioningPaymentData)1 Contact (com.autentia.tnt.businessobject.Contact)1 ContactInfo (com.autentia.tnt.businessobject.ContactInfo)1 Department (com.autentia.tnt.businessobject.Department)1 Interaction (com.autentia.tnt.businessobject.Interaction)1 Organization (com.autentia.tnt.businessobject.Organization)1 Locale (java.util.Locale)1 Matcher (java.util.regex.Matcher)1 FacesException (javax.faces.FacesException)1 UIColumn (javax.faces.component.UIColumn)1 UIInput (javax.faces.component.UIInput)1