Package net.sourceforge.stripes.validation

Examples of net.sourceforge.stripes.validation.ValidationMetadata


                    value = parameter.getDefaultValue();

                if (value != null) {
                    // format (and maybe encrypt) the value as a string
                    String formatted = format(value);
                    ValidationMetadata validation = validations.get(parameter.getName());
                    if (validation != null && validation.encrypted())
                        formatted = CryptoUtil.encrypt(formatted);

                    // if after formatting we still have a value then embed it in the URI
                    if (formatted != null && formatted.length() > 0) {
                        if (nextLiteral != null) {
View Full Code Here


                continue;
            }

            Class<?> fieldType = eval.getType();

            ValidationMetadata data = metadata.get(field);

            StringBuilder fieldInfo = new StringBuilder();

            if (fieldType.isPrimitive() || Number.class.isAssignableFrom(fieldType)
                    || Date.class.isAssignableFrom(fieldType) || includeType) {
                fieldInfo.append("type:").append(
                        JavaScriptBuilder.quote(fqn ? fieldType.getName() : fieldType
                                .getSimpleName()));
            }
           
            Class<?> typeConverterClass = null;
           
            if (data != null) {
                if (fieldInfo.length() > 0)
                    fieldInfo.append(',');

                fieldInfo.append("required:").append(data.required())
                        .append(",ignore:").append(data.ignore())
                        .append(",encrypted:").append(data.encrypted())
                        .append(",trim:").append(data.trim());

                if (data.on() != null) {
                    fieldInfo.append(",on:[");
                    Iterator<String> it = data.on().iterator();
                    while (it.hasNext()) {
                        fieldInfo.append(JavaScriptBuilder.quote(it.next()));
                        if (it.hasNext())
                            fieldInfo.append(",");
                    }
                    fieldInfo.append("]");
                }
                if (data.mask() != null)
                    fieldInfo.append(",mask:").append("new RegExp(")
                            .append(JavaScriptBuilder.quote("^" + data.mask().toString() + "$"))
                            .append(")");
                if (data.minlength() != null)
                    fieldInfo.append(",minlength:").append(data.minlength());
                if (data.maxlength() != null)
                    fieldInfo.append(",maxlength:").append(data.maxlength());
                if (data.minvalue() != null)
                    fieldInfo.append(",minvalue:").append(data.minvalue());
                if (data.maxvalue() != null)
                    fieldInfo.append(",maxvalue:").append(data.maxvalue());

                String label = data.label();
                if (data.label() == null) {
                    label = LocalizationUtility.getLocalizedFieldName(field, form == null ? null
                            : form.getAction(), form == null ? null : form.getActionBeanClass(),
                            locale);
                }
                if (label != null)
                    fieldInfo.append(",label:").append(JavaScriptBuilder.quote(label));

                typeConverterClass = data.converter();
            }

            // If we couldn't get the converter from the validation annotation
            // try to get it from the TypeConverterFactory
            if (typeConverterClass == null) {
View Full Code Here

            catch (MissingResourceException mre2) { /* do nothing */ }
        }

        // Lastly, check @Validate on the ActionBean property
        if (localizedValue == null && beanclass != null) {
            ValidationMetadata validate = StripesFilter.getConfiguration()
                    .getValidationMetadataProvider()
                    .getValidationMetadata(beanclass, parameterName);
            if (validate != null && validate.label() != null && !"".equals(validate.label())) {
                localizedValue = validate.label();
            }
        }

        return localizedValue;
    }
View Full Code Here

                if (!StripesConstants.SPECIAL_URL_KEYS.contains(pname)
                        && !fieldErrors.containsKey(pname)) {
                    log.trace("Running binding for property with name: ", name);

                    // Determine the target type
                    ValidationMetadata validationInfo = validationInfos.get(name.getStrippedName());
                    PropertyExpressionEvaluation eval;
                    try {
                        eval = new PropertyExpressionEvaluation(PropertyExpression
                                .getExpression(pname), bean);
                    }
                    catch (Exception e) {
                        if (pname.equals(context.getEventName()))
                            continue;
                        else
                            throw e;
                    }
                    Class<?> type = eval.getType();
                    Class<?> scalarType = eval.getScalarType();

                    // Check to see if binding into this expression is permitted
                    if (!isBindingAllowed(eval))
                        continue;

                    if (type == null
                            && (validationInfo == null || validationInfo.converter() == null)) {
                        if (!pname.equals(context.getEventName())) {
                            log.trace("Could not find type for property '", name.getName(),
                                    "' of '", bean.getClass().getSimpleName(),
                                    "' probably because it's not ",
                                    "a property of the bean.  Skipping binding.");
                        }
                        continue;
                    }
                    String[] values = entry.getValue();

                    // Do Validation and type conversion
                    List<ValidationError> errors = new ArrayList<ValidationError>();

                    // If the property should be ignored, skip to the next property
                    if (validationInfo != null && validationInfo.ignore()) {
                        continue;
                    }

                    if (validate && validationInfo != null) {
                        doPreConversionValidations(name, values, validationInfo, errors);
View Full Code Here

                .getValidationMetadataProvider().getValidationMetadata(bean.getClass());
        SortedMap<ParameterName, String[]> parameters = new TreeMap<ParameterName, String[]>();

        for (Map.Entry<String, String[]> entry : requestParameters.entrySet()) {
            ParameterName paramName = new ParameterName(entry.getKey().trim());
            ValidationMetadata validation = validations.get(paramName.getStrippedName());
            parameters.put(paramName, trim(entry.getValue(), validation));
        }

        return parameters;
    }
View Full Code Here

            boolean wizard = bean.getClass().getAnnotation(Wizard.class) != null;
            Collection<String> fieldsOnPage = getFieldsPresentInfo(bean);

            for (Map.Entry<String, ValidationMetadata> entry : validationInfos.entrySet()) {
                String propertyName = entry.getKey();
                ValidationMetadata validationInfo = entry.getValue();

                // If the field is required, and we don't have index params that collapse
                // to that property name, check that it was supplied
                if (validationInfo.requiredOn(context.getEventName())
                        && !indexedParams.contains(propertyName)) {

                    // Make the added check that if the form is a wizard, the required field is
                    // in the set of fields that were on the page
                    if (!wizard || fieldsOnPage.contains(propertyName)) {
                        String[] values = trim(request.getParameterValues(propertyName), validationInfo);

                        // Decrypt encrypted fields before checking for null
                        if (validationInfo.encrypted()) {
                            for (int i = 0, n = values.length; i < n; i++) {
                                if (values[i] != null)
                                    values[i] = CryptoUtil.decrypt(values[i]);
                            }
                        }

                        log.debug("Checking required field: ", propertyName, ", with values: ", values);
                        checkSingleRequiredField(propertyName, propertyName, values, stripesReq, errors);
                    }
                }
            }
        }

        // Now the easy work is done, figure out which rows of indexed props had values submitted
        // and what to flag up as failing required field validation
        if (indexedParams.size() > 0) {
            Map<String, Row> rows = new HashMap<String, Row>();

            for (Map.Entry<ParameterName, String[]> entry : parameters.entrySet()) {
                ParameterName name = entry.getKey();
                String[] values = entry.getValue();

                if (name.isIndexed()) {
                    String rowKey = name.getName().substring(0, name.getName().indexOf(']') + 1);
                    if (!rows.containsKey(rowKey)) {
                        rows.put(rowKey, new Row());
                    }

                    rows.get(rowKey).put(name, values);
                }
            }

            for (Row row : rows.values()) {
                if (row.hasNonEmptyValues()) {
                    for (Map.Entry<ParameterName, String[]> entry : row.entrySet()) {
                        ParameterName name = entry.getKey();
                        String[] values = entry.getValue();
                        ValidationMetadata validationInfo = validationInfos.get(name.getStrippedName());

                        if (validationInfo != null
                                && validationInfo.requiredOn(context.getEventName())) {
                            checkSingleRequiredField(name.getName(), name.getStrippedName(),
                                    values, stripesReq, errors);
                        }
                    }
                }
View Full Code Here

                .getValidationMetadataProvider().getValidationMetadata(bean.getClass());
        for (Map.Entry<ParameterName, List<Object>> entry : convertedValues.entrySet()) {
            // Sort out what we need to validate this field
            ParameterName name = entry.getKey();
            List<Object> values = entry.getValue();
            ValidationMetadata validationInfo = validationInfos.get(name.getStrippedName());

            if (values.size() == 0 || validationInfo == null) {
                continue;
            }

            for (Object value : values) {
                // If the value is a number then we should check to see if there are range
                // boundaries
                // established, and check them.
                if (value instanceof Number) {
                    Number number = (Number) value;

                    if (validationInfo.minvalue() != null
                            && number.doubleValue() < validationInfo.minvalue()) {
                        ValidationError error = new ScopedLocalizableError("validation.minvalue",
                                "valueBelowMinimum", validationInfo.minvalue());
                        error.setFieldValue(String.valueOf(value));
                        errors.add(name.getName(), error);
                    }

                    if (validationInfo.maxvalue() != null
                            && number.doubleValue() > validationInfo.maxvalue()) {
                        ValidationError error = new ScopedLocalizableError("validation.maxvalue",
                                "valueAboveMaximum", validationInfo.maxvalue());
                        error.setFieldValue(String.valueOf(value));
                        errors.add(name.getName(), error);
                    }
                }
            }
View Full Code Here

        String formatted = (formatter == null) ? String.valueOf(input) : formatter.format(input);

        // encrypt the formatted value if required
        if (forOutput && formatted != null) {
            try {
                ValidationMetadata validate = getValidationMetadata();
                if (validate != null && validate.encrypted())
                    formatted = CryptoUtil.encrypt(formatted);
            }
            catch (JspException e) {
                throw new StripesRuntimeException(e);
            }
View Full Code Here

TOP

Related Classes of net.sourceforge.stripes.validation.ValidationMetadata

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.