Package org.apache.commons.validator

Examples of org.apache.commons.validator.Form


                ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(),
                PageContext.APPLICATION_SCOPE);

        Locale locale = RequestUtils.retrieveUserLocale(this.pageContext, null);

        Form form = resources.get(locale, formName);
        if (form != null) {
            if ("true".equalsIgnoreCase(dynamicJavascript)) {
                MessageResources messages =
                    (MessageResources) pageContext.getAttribute(
                        bundle + config.getPrefix(),
                        PageContext.APPLICATION_SCOPE);

                List lActions = new ArrayList();
                List lActionMethods = new ArrayList();

                // Get List of actions for this Form
                for (Iterator i = form.getFields().iterator(); i.hasNext();) {
                    Field field = (Field) i.next();

                    for (Iterator x = field.getDependencies().iterator(); x.hasNext();) {
                        Object o = x.next();

                        if (o != null && !lActionMethods.contains(o)) {
                            lActionMethods.add(o);
                        }
                    }

                }

                // Create list of ValidatorActions based on lActionMethods
                for (Iterator i = lActionMethods.iterator(); i.hasNext();) {
                    String depends = (String) i.next();
                    ValidatorAction va = resources.getValidatorAction(depends);

                    // throw nicer NPE for easier debugging
                    if (va == null) {
                        throw new NullPointerException(
                            "Depends string \""
                                + depends
                                + "\" was not found in validator-rules.xml.");
                    }              
                   
                    String javascript = va.getJavascript();
                    if (javascript != null && javascript.length() > 0) {
                        lActions.add(va);
                    } else {
                        i.remove();
                    }
                }

                Collections.sort(lActions, new Comparator() {
                    public int compare(Object o1, Object o2) {
                        ValidatorAction va1 = (ValidatorAction) o1;
                        ValidatorAction va2 = (ValidatorAction) o2;

                        if ((va1.getDepends() == null || va1.getDepends().length() == 0)
                            && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                            return 0;
                        } else if (
                            (va1.getDepends() != null && va1.getDepends().length() > 0)
                                && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                            return 1;
                        } else if (
                            (va1.getDepends() == null || va1.getDepends().length() == 0)
                                && (va2.getDepends() != null && va2.getDepends().length() > 0)) {
                            return -1;
                        } else {
                            return va1.getDependencies().size() - va2.getDependencies().size();
                        }
                    }
                });

                String methods = null;
                for (Iterator i = lActions.iterator(); i.hasNext();) {
                    ValidatorAction va = (ValidatorAction) i.next();

                    if (methods == null) {
                        methods = va.getMethod() + "(form)";
                    } else {
                        methods += " && " + va.getMethod() + "(form)";
                    }
                }

                results.append(getJavascriptBegin(methods));

                for (Iterator i = lActions.iterator(); i.hasNext();) {
                    ValidatorAction va = (ValidatorAction) i.next();
                    String jscriptVar = null;
                    String functionName = null;

                    if (va.getJsFunctionName() != null && va.getJsFunctionName().length() > 0) {
                        functionName = va.getJsFunctionName();
                    } else {
                        functionName = va.getName();
                    }

                    if (isStruts11()) {
                        results.append("    function " +
                                       functionName + " () { \n");
                    } else {
                        results.append("    function " +
                                       formName + "_" + functionName + " () { \n");
                    }
                    for (Iterator x = form.getFields().iterator(); x.hasNext();) {
                        Field field = (Field) x.next();

                        // Skip indexed fields for now until there is a good way to handle
                        // error messages (and the length of the list (could retrieve from scope?))
                        if (field.isIndexed()
View Full Code Here


                + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
        }       

        Locale locale = TagUtils.getInstance().getUserLocale(this.pageContext, null);

        Form form = resources.getForm(locale, formName);

        if ("true".equalsIgnoreCase(dynamicJavascript) && form == null)
        {
            throw new JspException("No form found under '"
                                   + formName
View Full Code Here

    {
        StringBuffer results = new StringBuffer();

        Locale locale = StrutsUtils.getLocale(request, session);

        Form form = resources.get(locale, formName);
        if (form != null)
        {
            results.append(getDynamicJavascript(resources, locale, form));
        }
View Full Code Here

    {
        StringBuilder results = new StringBuilder();

        Locale locale = StrutsUtils.getLocale(request, session);

        Form form = resources.getForm(locale, formName);
        if (form != null)
        {
            results.append(getDynamicJavascript(resources, locale, form));
        }
View Full Code Here

            (ValidatorResources)app.getAttribute(ValidatorPlugIn.VALIDATOR_KEY +
                                                 config.getPrefix());

        Locale locale = StrutsUtils.getLocale(request, session);

        Form form = resources.get(locale, formName);
        if (form != null)
        {
            if(this.dynamicJavascript)
            {
                results.append(getDynamicJavascript(resources, locale, form));
View Full Code Here

        ValidatorResources resources) {
           
        boolean success = true;

        // Start by getting the form for the current locale and Bean.
        Form form = resources.getForm(Locale.getDefault(), "ValidateBean");

        System.out.println("\n\nValidating:");
        System.out.println(bean);

        // Iterate over each of the properties of the Bean which had messages.
        Iterator propertyNames = results.getPropertyNames().iterator();
        while (propertyNames.hasNext()) {
            String propertyName = (String) propertyNames.next();

            // Get the Field associated with that property in the Form
            Field field = form.getField(propertyName);

            // Look up the formatted name of the field from the Field arg0
            String prettyFieldName = apps.getString(field.getArg(0).getKey());

            // Get the result of validating the property.
View Full Code Here

                ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(),
                PageContext.APPLICATION_SCOPE);

        Locale locale = RequestUtils.retrieveUserLocale(this.pageContext, null);

        Form form = resources.get(locale, formName);
        if (form != null) {
            if ("true".equalsIgnoreCase(dynamicJavascript)) {
                MessageResources messages =
                    (MessageResources) pageContext.getAttribute(
                        bundle + config.getPrefix(),
                        PageContext.APPLICATION_SCOPE);

                List lActions = new ArrayList();
                List lActionMethods = new ArrayList();

                // Get List of actions for this Form
                for (Iterator i = form.getFields().iterator(); i.hasNext();) {
                    Field field = (Field) i.next();

                    for (Iterator x = field.getDependencies().iterator(); x.hasNext();) {
                        Object o = x.next();

                        if (o != null && !lActionMethods.contains(o)) {
                            lActionMethods.add(o);
                        }
                    }

                }

                // Create list of ValidatorActions based on lActionMethods
                for (Iterator i = lActionMethods.iterator(); i.hasNext();) {
                    String depends = (String) i.next();
                    ValidatorAction va = resources.getValidatorAction(depends);

                    // throw nicer NPE for easier debugging
                    if (va == null) {
                        throw new NullPointerException(
                            "Depends string \""
                                + depends
                                + "\" was not found in validator-rules.xml.");
                    }              
                   
                    String javascript = va.getJavascript();
                    if (javascript != null && javascript.length() > 0) {
                        lActions.add(va);
                    } else {
                        i.remove();
                    }
                }

                Collections.sort(lActions, new Comparator() {
                    public int compare(Object o1, Object o2) {
                        ValidatorAction va1 = (ValidatorAction) o1;
                        ValidatorAction va2 = (ValidatorAction) o2;

                        if ((va1.getDepends() == null || va1.getDepends().length() == 0)
                            && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                            return 0;
                        } else if (
                            (va1.getDepends() != null && va1.getDepends().length() > 0)
                                && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                            return 1;
                        } else if (
                            (va1.getDepends() == null || va1.getDepends().length() == 0)
                                && (va2.getDepends() != null && va2.getDepends().length() > 0)) {
                            return -1;
                        } else {
                            return va1.getDependencies().size() - va2.getDependencies().size();
                        }
                    }
                });

                String methods = null;
                for (Iterator i = lActions.iterator(); i.hasNext();) {
                    ValidatorAction va = (ValidatorAction) i.next();

                    if (methods == null) {
                        methods = va.getMethod() + "(form)";
                    } else {
                        methods += " && " + va.getMethod() + "(form)";
                    }
                }

                results.append(getJavascriptBegin(methods));

                for (Iterator i = lActions.iterator(); i.hasNext();) {
                    ValidatorAction va = (ValidatorAction) i.next();
                    String jscriptVar = null;
                    String functionName = null;

                    if (va.getJsFunctionName() != null && va.getJsFunctionName().length() > 0) {
                        functionName = va.getJsFunctionName();
                    } else {
                        functionName = va.getName();
                    }

                    results.append("    function " + functionName + " () { \n");
                    for (Iterator x = form.getFields().iterator(); x.hasNext();) {
                        Field field = (Field) x.next();

                        // Skip indexed fields for now until there is a good way to handle
                        // error messages (and the length of the list (could retrieve from scope?))
                        if (field.isIndexed()
View Full Code Here

    {

        boolean success = true;

        // Start by getting the form for the current locale and Bean.
        Form form = resources.getForm(Locale.getDefault(), formName);

        System.out.println("\n\nValidating:");
        System.out.println(bean);

        // Iterate over each of the properties of the Bean which had messages.
        Iterator propertyNames = results.getPropertyNames().iterator();
        while (propertyNames.hasNext())
        {
            String propertyName = (String) propertyNames.next();

            // Get the Field associated with that property in the Form
            Field field = form.getField(propertyName);

            // Look up the formatted name of the field from the Field arg0
            String prettyFieldName = propertyName; //apps.getString(field.getArg(0).getKey());

            // Get the result of validating the property.
View Full Code Here

        // get the name of the bean from the key
        String formName = key.substring(0, key.indexOf('.'));
        String fieldName = key.substring(formName.length() + 1);

        if (resources != null) {
            Form form = resources.getForm(locale, formName);

            if (form != null) {
                Field field = form.getField(fieldName);

                if (field != null) {
                    if (field.isDependency("required") || field.isDependency("validwhen")) {
                        requiredField = true;
                    }
View Full Code Here

    protected static Arg[] getArgs(String name, String ruleName) {

        StringBuffer formName = new StringBuffer(FORM_NAME_PREFIX);
        formName.append(ruleName);

        Form formDef = getValidatorResources().getForm(Locale.getDefault(), formName.toString());
        assert formDef != null;

        Field field = formDef.getField(ruleName);
        assert field != null;

        Arg[] templateArgs = field.getArgs(name);

        int max = -1;
View Full Code Here

TOP

Related Classes of org.apache.commons.validator.Form

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.