Package org.apache.commons.validator

Examples of org.apache.commons.validator.ValidatorAction


                }

                // 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()
                            && field.getPage() == page
                            && field.isDependency(va.getName())) {
                            String message = Resources.getMessage(messages, locale, va, field);
                            message = (message != null ? message : "");

                            jscriptVar = getNextVar(jscriptVar);
View Full Code Here


        StringBuffer sb = new StringBuffer();

        sb.append("\n\n");

        for (Iterator i = resources.getValidatorActions().values().iterator(); i.hasNext();) {
            ValidatorAction va = (ValidatorAction) i.next();
            if (va != null) {
                String javascript = va.getJavascript();
                if (javascript != null && javascript.length() > 0) {
                    sb.append(javascript + "\n");
                }
            }
        }
View Full Code Here

                }
       
        results.append(this.getJavascriptBegin(methods));

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


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

           
            results.append("    function " + jsFormName + "_" + 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()
                    || field.getPage() != page
                    || !field.isDependency(va.getName())) {

                    continue;
                }

                String message = Resources.getMessage(messages, locale, va, field);
View Full Code Here

        StringBuffer methods = new StringBuffer();
        final String methodOperator = stopOnError ? " && " : " & ";

        Iterator iter = actions.iterator();
        while (iter.hasNext()) {
            ValidatorAction va = (ValidatorAction) iter.next();

            if (methods.length() > 0) {
                methods.append(methodOperator);
            }
            methods.append(va.getMethod())
                   .append("(form)");
        }

        return methods.toString();
    }
View Full Code Here

        // Create list of ValidatorActions based on actionMethods
        iterator = actionMethods.iterator();
        while (iterator.hasNext()) {
            String depends = (String) iterator.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.");
            }

            if (va.getJavascript() != null && va.getJavascript().length() > 0) {
                actions.add(va);
            } else {
                iterator.remove();
            }
        }
View Full Code Here

        sb.append("\n\n");

        Iterator actions = resources.getValidatorActions().values().iterator();
        while (actions.hasNext()) {
            ValidatorAction va = (ValidatorAction) actions.next();
            if (va != null) {
                String javascript = va.getJavascript();
                if (javascript != null && javascript.length() > 0) {
                    sb.append(javascript + "\n");
                }
            }
        }
View Full Code Here


    // Test retrieving resources
    public void testResources() {

        ValidatorAction action = null;

        ValidatorResources resources = validator.resources(facesContext);
        assertNotNull(resources);

        action = resources.getValidatorAction("integer");
View Full Code Here

        Iterator entries = ACTION_COUNTS.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            String key = (String) entry.getKey();
            Integer value = (Integer) entry.getValue();
            ValidatorAction va = resources.getValidatorAction(key);
            assertTrue("ValidatorAction " + key + " is present", va != null);
            ShaleValidatorAction[] action = (ShaleValidatorAction[])
              actions.get(key);
            assertTrue("ShaleValidatorAction[] " + key + " is present", action != null);
            assertEquals("ShaleValidatorAction[] " + key + " has correct size",
View Full Code Here

        //set the value
        component1.setSubmittedValue("0123456789");
        // invoke component validation
        component1.validate(facesContext);
                       
        ValidatorAction va = CommonsValidator.getValidatorAction("maxlength");
        assertNotNull("validator action", va);
        String actualMsg = messages.getMessage(va.getMsg(),
                facesContext.getViewRoot().getLocale(),
                new Object[] {component1.getId(),
                validator1.getVars().get(CommonsValidator.MAX_LENGTH_VARNAME)});

        // check for a error message
View Full Code Here

        //set the value
        component1.setSubmittedValue("0");
        // invoke component validation
        component1.validate(facesContext);

        ValidatorAction va = CommonsValidator.getValidatorAction("minlength");
        assertNotNull("validator action", va);
        String actualMsg = messages.getMessage(va.getMsg(),
                facesContext.getViewRoot().getLocale(),
                new Object[] {component1.getId(),
                validator1.getVars().get(CommonsValidator.MIN_LENGTH_VARNAME)});

        // check for a error message
View Full Code Here

TOP

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

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.