Package org.openfaces.org.json

Examples of org.openfaces.org.json.JSONObject



    @Override
    public JSONObject process(ExpressionFilterCriterion criterion) {
        try {
            JSONObject result = new JSONObject();
            result.put(TYPE, CriterionType.EXPRESSION);
            result.put(PROPERTY_LOCATOR_EXPRESSION, criterion.getPropertyLocator().getExpression());

            JSONObject jsonParameters = new JSONObject();
            Map<String, Object> parameters = criterion.getParameters();
            for (String parameterName : parameters.keySet()) {
                Object parameterValue = criterion.getParameters().get(parameterName);
                JSONObject jsonParameterValue = new JSONObject();
                ParameterType parameterType;
                if (parameterValue instanceof Date) {
                    parameterType = ParameterType.DATE;
                    parameterValue = ((Date) parameterValue).getTime();
                } else if (isNumberType(parameterValue.getClass())) {
                    parameterType = ParameterType.NUMBER;
                } else if (isBooleanType(parameterValue.getClass())) {
                    parameterType = ParameterType.BOOLEAN;
                } else {
                    parameterType = ParameterType.TEXT;
                    parameterValue = parameterValue.toString();
                }

                jsonParameterValue.put(PARAMETER_TYPE, parameterType);
                jsonParameterValue.put(PARAMETER_VALUE, parameterValue);
                jsonParameters.put(parameterName, jsonParameterValue);
            }
            result.put(PARAMETERS, jsonParameters);
            result.put(FILTER_CONDITION_NAME, criterion.getCondition().getName());
            result.put(INVERSE, criterion.isInverse());
View Full Code Here


        return process(criterion, CriterionType.OR);
    }

    private JSONObject process(CompositeFilterCriterion criterion, CriterionType type) {
        try {
            JSONObject result = new JSONObject();
            result.put(TYPE, type);
            JSONArray criteria = new JSONArray();
            for (FilterCriterion childCriterion : criterion.getCriteria()) {
                criteria.put(childCriterion.process(this));
            }
            result.put(CRITERIA, criteria);
            return result;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here

        if (!Rendering.isNullOrEmpty(headerClassName))
            initObject.put("headingsClassName", headerClassName);
    }

    private JSONObject getCommonHeaderParam(TableStructure tableStructure) throws JSONException {
        JSONObject result = new JSONObject();
        FacesContext context = FacesContext.getCurrentInstance();
        AbstractTable table = ((AbstractTable) tableStructure.getComponent());
        String commonHeaderClass = Styles.getCSSClass(context, tableStructure.getComponent(),
                isHeader ? table.getCommonHeaderRowStyle() : table.getCommonFooterRowStyle(),
                isHeader ? table.getCommonHeaderRowClass() : table.getCommonFooterRowClass());
        if (!Rendering.isNullOrEmpty(commonHeaderClass))
            result.put("className", commonHeaderClass);
        return result;
    }
View Full Code Here

            result.put("className", commonHeaderClass);
        return result;
    }

    private JSONObject getSubHeaderParam(TableStructure tableStructure) throws JSONException {
        JSONObject result = new JSONObject();
        FacesContext context = FacesContext.getCurrentInstance();
        AbstractTable table = ((AbstractTable) tableStructure.getComponent());
        String className = Styles.getCSSClass(context, table, getSubHeaderRowStyle(table),
                StyleGroup.regularStyleGroup(), getSubHeaderRowClass(table), DEFAULT_SUBHEADER_ROW_CELLS_CLASS);
        if (!Rendering.isNullOrEmpty(className))
            result.put("className", className);

        return result;
    }
View Full Code Here

    public TableSection(TableElement parent) {
        super(parent);
    }

    public JSONObject getInitParam(TableStyles defaultStyles) {
        JSONObject result = new JSONObject();

        try {
            fillInitParam(result, defaultStyles);
        } catch (JSONException e) {
            throw new RuntimeException(e);
View Full Code Here

        List<SortingRule> sortingRules = new ArrayList<SortingRule>();
        try {
            JSONArray sortingRulesJson = new JSONArray(sortingRulesStr);
            for (int i = 0, count = sortingRulesJson.length(); i < count; i++) {
                JSONObject jsonObject = sortingRulesJson.getJSONObject(i);
                sortingRules.add(new SortingRule(jsonObject));
            }
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
View Full Code Here

            scrolling.processUpdates(context);
            return null;
        }
        if ("rows".equals(portionName)) {
            beforeReloadingAllRows(context, table);
            JSONObject result = serveDynamicRowsRequest(context, table, 0, Integer.MAX_VALUE);

            ScriptBuilder sb = new ScriptBuilder();
            encodeAdditionalFeaturesOnBodyReload(context, table, sb);
            Rendering.renderInitScript(context, sb);
View Full Code Here

                context.setResponseWriter(responseWriter);
            }
            table.setRowIndex(-1);
            responseWriter.write(stringWriter.toString());

            JSONObject rowsInitInfo = new JSONObject();
            fillDynamicRowsInitInfo(context, table, rowIndex, rowCount, tableStructure, rowsInitInfo);
            return rowsInitInfo;
        } finally {
            table.getAttributes().remove(TableStructure.TABLE_STRUCTURE_ATTR);
        }
View Full Code Here

    }

    protected static boolean encodeFoldingSupport(FacesContext context,
                                                  ScriptBuilder buf,
                                                  AbstractTable table) throws IOException {
        JSONObject treeStructure = formatTreeStructureMap(context, table, -1, -1);
        if (treeStructure == null) {
            // this can be the case for a grouping-enabled table which doesn't have any grouping rule configured,
            // which means that it is displayed as a plain list and no special hierarchy handling is required
            return false;
        }
View Full Code Here

    protected static JSONObject formatTreeStructureMap(
            FacesContext context,
            AbstractTable table,
            int fromRowIndex,
            int rowCount) {
        JSONObject result = new JSONObject();
        Map<Object, ? extends NodeInfo> structureMap = table.getTreeStructureMap(context);
        if (structureMap == null)
            return null;
        Set<? extends Map.Entry<Object, ? extends NodeInfo>> entries = structureMap.entrySet();
        for (Map.Entry<Object, ? extends NodeInfo> entry : entries) {
            Object rowIndex = entry.getKey();
            if (fromRowIndex != -1) {
                if (!(rowIndex instanceof Integer))
                    continue;
                int intRowIndex = (Integer) rowIndex;
                if (intRowIndex < fromRowIndex || intRowIndex >= fromRowIndex + rowCount)
                    continue;
                intRowIndex -= fromRowIndex;
                rowIndex = intRowIndex;
            }
            NodeInfo expansionData = entry.getValue();
            boolean nodeHasChildren = expansionData.getNodeHasChildren();
            Object childCount = nodeHasChildren
                    ? (expansionData.getChildrenPreloaded() ? String.valueOf(expansionData.getChildNodeCount()) : "?")
                    : 0;
            try {
                result.put(String.valueOf(rowIndex), childCount);
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }
        return result;
View Full Code Here

TOP

Related Classes of org.openfaces.org.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.