Package org.apache.tapestry.form

Examples of org.apache.tapestry.form.AbstractFormComponent


     * @param activity
     * @param render
     */
    private void addValidation(FlowActivity activity, IRender render) {
        if (render instanceof AbstractFormComponent && render instanceof ValidatableField) {
            AbstractFormComponent formComponent = (AbstractFormComponent) render;
            IBinding alreadyBinding = formComponent.getBinding(ALREADY_ADDED_BINDING);
            if ( alreadyBinding == null) {
                FlowPropertyDefinition definition = activity.getFlowPropertyDefinition(this.key);
                if ( definition != null) {
                    IBinding validatorsBinding = formComponent.getBinding(VALIDATORS);
                    if (definition.isDynamic()) {
                        IBinding htmlClassBinding = formComponent.getBinding(HTML_CLASS);
                        IBinding htmlOnBlurBinding = formComponent.getBinding(HTML_ONBLUR);
                        String htmlClassToAdd = "refresh-" + formComponent.getClientId();
                        String htmlClass = null;
                        if ( htmlClassBinding == null) {
                            htmlClass= htmlClassToAdd;
                        } else if (htmlClassBinding instanceof LiteralBinding) {
                            htmlClass =(String)htmlClassBinding.getObject(String.class) + " "+htmlClassToAdd;
                        } else {
                            getLog().debug(activity.getFullActivityInstanceNamespace()+ ": cannot add class to component="+formComponent);
                        }
                        if (htmlClass != null) {
                            formComponent.setBinding(HTML_CLASS, new LiteralBinding("html class", valueConverter, location, htmlClass));
                        }
                        if (htmlOnBlurBinding == null) {
                            String htmlOnBlurValue = "javascript:amplafi.util.refreshIfChanged(this);";
                            formComponent.setBinding(HTML_ONBLUR, new LiteralBinding("html on blur", valueConverter, location, htmlOnBlurValue));

                        } else {
                            getLog().debug(activity.getFullActivityInstanceNamespace()+ ": cannot add onblur to component="+formComponent);
                        }
                    }
                    if (validatorsBinding == null) {
                        String validators = definition.getValidators();
                        if ( definition.getPropertyRequired() == FlowActivityPhase.advance) {
                            if ( isBlank(validators)) {
                                validators = REQUIRED;
                            } else {
                                // may re-add required if already present - seems like a minor issue
                                validators = REQUIRED + "," + validators;
                            }
                        }
                        if (isNotBlank(validators)) {
                            validatorsBinding = this.validationBindingFactory.createBinding(formComponent, "", validators, null);
                            formComponent.setBinding(VALIDATORS, validatorsBinding);
                        }
                    } else if ( getLog().isDebugEnabled()){
                        getLog().debug(activity.getFullActivityInstanceNamespace()+": property binding "+this+": make sure that @Parameter(cache=false) is set because first access is not by a ValidatableField component");
                    }
                }
                // avoid constantly re-adding the bindings
                // HACK: this however results in adding the attribute to all html nodes using a FlowPropertyBinding.
                formComponent.setBinding(ALREADY_ADDED_BINDING, new LiteralBinding(ALREADY_ADDED_BINDING, valueConverter, location, "true"));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry.form.AbstractFormComponent

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.