Package com.volantis.mcs.protocols.widgets.attributes

Examples of com.volantis.mcs.protocols.widgets.attributes.ValidateAttributes


        messageAttributes.setType(messageType);

        if (parent instanceof ValidateElement) {
            ValidateElement validateElement = (ValidateElement) parent;
           
            ValidateAttributes validateAttributes = validateElement.getValidateAttributes();

            VolantisProtocol protocol = getProtocol(context);
           
            // Generate ID for the message element
            if (messageAttributes.getId() == null) {
                messageAttributes.setId(protocol.getMarinerPageContext()
                        .generateUniqueFCID());
            }
           
            // Process the 'type' attribute, and propagate it to the enclosing validate element.
            if ((messageType == null) || messageType.equals("invalid")) {
                validateAttributes.setInvalidMessageElementId(messageAttributes.getId());
            } else if (messageType.equals("empty")) {
                validateAttributes.setEmptyMessageElementId(messageAttributes.getId());
            }
        }
    }
View Full Code Here


        // Validate element lies inside not-validable xf:input element,
        // so its validation strategy must be AnywhereStrategy.
        super(WidgetElements.VALIDATE, UnstyledStrategy.STRATEGY,
                context);

        protocolAttributes = new ValidateAttributes();
    }
View Full Code Here

            throw new XDIMEException(e);
        }       
        // At this point we are sure that the widget is supported,
        // so it makes sense to do all the initialization
       
        ValidateAttributes validateAttributes = (ValidateAttributes) protocolAttributes;

        // Generate ID for the Validator widget.
        if (validateAttributes.getId() == null) {
            validateAttributes.setId(getProtocol(context)
                    .getMarinerPageContext().generateUniqueFCID());
        }

        validateAttributes.setMessageArea(attributes.getValue("", "message-area"));
        validateAttributes.setSrc(getSrcAttributeValue(context, attributes));
        validateAttributes.setMessagePopup(attributes.getValue("", "message-popup"));

        String auto = attributes.getValue("", "auto");
        validateAttributes.setAuto((auto == null) || (!auto.equals("no")));

        // Set flag, indicating whether the validate element
        // is used as a part of simple or multiple validator.
        validateAttributes
                .setMultiple(parent instanceof MultipleValidatorElement);

        if (parent instanceof XFInputElementImpl) {
            MCSAttributes inputAttributes = ((XFInputElementImpl) parent)
                    .getProtocolAttributes();

            // If input element does not have an ID, generate it now,
            // because JavaScript Widget.SimpleValidator class needs
            // to use it as a reference
            if (inputAttributes.getId() == null) {
                inputAttributes.setId(getProtocol(context)
                        .getMarinerPageContext().generateUniqueFCID());
            }

            // Store the ID in validate attributes, for easy access.
            validateAttributes.setInputElementId(inputAttributes.getId());

//            temporarily changed (VMS-321) and implemented in javascript as event type should depends on device policy
//            which will say if browser supports mouse cursor or not.
//            For exmple for NetFront3.4 in SE K660i onblur will be replaced with onmouseout
//            Empty events attribute will be rendered and will be filled in javascript
            if (validateAttributes.isAuto()) {
//               This needs to be done using timers, because without timers the autoFocus feature does not work.
//               String validateString = "setTimeout(function(){Widget.getInstance('"
//                        + validateAttributes.getId() + "').validate()}, 0)";

                String validateString = "";
                inputAttributes.getEventAttributes(true).setEvent(
                        EventConstants.ON_BLUR, validateString);
                inputAttributes.getEventAttributes(true).setEvent(
                        EventConstants.ON_MOUSE_OUT, validateString);
            }

            // Set up the styles extractor to extract the MCS_INVALID value. Set
            // that value in the
            // ValidateAttributes object so that the extractor can use the value
            // when it is run. The
            // value used here is from a pseduoclass.

            // Extract styles from 'mcs-invalid' pseudo-class,
            // to be used to emphasise validation errors.
            StylesExtractor stylesExtractor =
                WidgetHelper.createStylesExtractor(null, inputAttributes.getStyles());
            stylesExtractor.setPseudoClass(StatefulPseudoClasses.MCS_INVALID);
            String invalidStyles = stylesExtractor.getJavaScriptStyles();

            validateAttributes.setInvalidStyle(invalidStyles);

            stylesExtractor.setPseudoClass(null);

            boolean containsMessageAction = stylesExtractor
                    .containsMessageValidationErrorAction();
            validateAttributes
                    .setContainsMessageValidationErrorAction(containsMessageAction);

            boolean containsFocusAction = stylesExtractor
                    .containsFocusValidationErrorAction();
            validateAttributes
                    .setContainsFocusValidationErrorAction(containsFocusAction);

            String inputFormat = stylesExtractor.getInputFormat();
            validateAttributes.setInputFormat(inputFormat);
        }
    }
View Full Code Here

        // anything.
        if(!isWidgetSupported(protocol)) {
            return;
        }

        ValidateAttributes validateAttributes = (ValidateAttributes) attributes;

        if (!validateAttributes.isMultiple()) {
            // This is rendering code for simple validator.

            // Create invisible styles for <span> element, which would
            // contain rendered content of the validation messages.
            Styles styles = StylingFactory.getDefaultInstance().createInheritedStyles(
                    protocol.getMarinerPageContext().getStylingEngine().getStyles(),
                    DisplayKeywords.NONE);

            // Open invisible <span> element
            DOMOutputBuffer currentBuffer = getCurrentBuffer(protocol);

            currentBuffer.openStyledElement("span", styles);

        } else {
            // This is rendering code multiple validator.

            WidgetDefaultModule widgetModule = (WidgetDefaultModule) protocol.getWidgetModule();

            MultipleValidatorBuilder builder = widgetModule.getMultipleValidatorBuilder();

            MultipleValidator validator = builder.getCurrentMultipleValidator();

            validator.setSourceURL(validateAttributes.getSrc());

            if (validateAttributes.getMessageArea() != null) {
                validator.setMessageArea(validateAttributes.getMessageArea());
            }

            if (validateAttributes.getMessagePopup() != null) {
                validator.setMessagePopup(validateAttributes.getMessagePopup());
            }
        }
    }
View Full Code Here

        // Handle protocol parametrisation.
        if(!isWidgetSupported(protocol)) {
            return;
        }

        ValidateAttributes validateAttributes = (ValidateAttributes) attributes;

        // Rendering is different, if validate element is used in simple
        // validator or in multiple validator.
        if (!validateAttributes.isMultiple()) {
            // Close invisible <span> element containg content of
            // the validation messages
            DOMOutputBuffer currentBuffer = getCurrentBuffer(protocol);

            currentBuffer.closeElement("span");

            require(WIDGET_VALIDATOR, protocol, attributes);
           
            // Gather all required validate attributes.
            String messageArea = validateAttributes.getMessageArea();

            String messagePopup = validateAttributes.getMessagePopup();

            // Render JavaScript
            ScriptAttributes scriptAttributes = new ScriptAttributes();

            scriptAttributes.setLanguage("JavaScript");

            scriptAttributes.setType("text/javascript");

            openScriptElement(scriptAttributes, currentBuffer);

            StringWriter scriptWriter = new StringWriter();

            try {
                scriptWriter.write("Widget.register(" + createJavaScriptString(validateAttributes.getId()) + ",");
                scriptWriter.write("new Widget.SimpleValidator({");
                scriptWriter.write("inputId:" + createJavaScriptString(validateAttributes.getInputElementId()));

                // Render input format
                String inputFormat = validateAttributes.getInputFormat();
                if (inputFormat != null) {
                    scriptWriter.write(", inputFormat:" + createJavaScriptString(inputFormat));
                }

                // Render URL of the validator
                String src = validateAttributes.getSrc();
                if (src != null) {
                    scriptWriter.write(", url:" + createJavaScriptString(src));
                }

                // Render styles for input element
                scriptWriter.write(", invalidInputStyle: " + validateAttributes.getInvalidStyle());

                // Render message-area stuff.
                if (validateAttributes.containsMessageValidationErrorAction()) {
                    // Render message for 'empty-input' validation error.
                    String emptyMessageElementId = validateAttributes.getEmptyMessageElementId();

                    if (emptyMessageElementId != null) {
                        scriptWriter.write(", emptyMessageId:" + createJavaScriptString(emptyMessageElementId));

                    } else {
                        String emptyMessage = messageLocalizer.format("input-required");

                        scriptWriter.write(", emptyMessage:" + createJavaScriptString(emptyMessage + "."));
                    }

                    // Render message for 'invalid-input' validation error.
                    String invalidMessageElementId = validateAttributes
                            .getInvalidMessageElementId();

                    if (invalidMessageElementId != null) {
                        scriptWriter.write(", invalidMessageId:" + createJavaScriptString(invalidMessageElementId));

                    } else {
                        String invalidMessage = messageLocalizer.format("input-invalid");

                        scriptWriter.write(", invalidMessage:" + createJavaScriptString(invalidMessage + "."));
                    }

                    // If there's no messageArea and no messagePopup are
                    // specified, display validation failures in default
                    // JavaScript alert.
                    // Otherwise, display message in message-area (if
                    // specified), and display popup instance (if specified).
                    // Note, that message-area can refer to content inside
                    // the popup instance. The effect would be that before
                    // popup is shows, its content is filled with specified
                    // message.
                    if ((messageArea == null) && (messagePopup == null)) {
                        scriptWriter.write(", displayAlerts: true");

                    } else {
                        if (messageArea != null) {
                            scriptWriter.write(", messageAreaId: " + createJavaScriptString(messageArea));
                        }

                        if (messagePopup != null) {
                            scriptWriter.write(", popupId: " + createJavaScriptString(messagePopup));
                        }
                    }
                }

                // Render autoFocus attribute
                if (validateAttributes.containsFocusValidationErrorAction()) {
                    scriptWriter.write(", autoFocus: true");
                }

                // Close all parentheses.
                scriptWriter.write("}));");

                // Register the same instance of widget under the ID of the
                // input field, so that it can be accessed from multiple validator
                // on client-side.
                // TODO: This is only temporary solution. Ideal solution would be
                // to pass list of simple validators instances directly in the
                // constructor of multiple validator.
                scriptWriter.write("Widget.register("
                        + createJavaScriptString(validateAttributes.getInputElementId())
                        + ", Widget.getInstance(" + createJavaScriptString(validateAttributes.getId()) + "));");

                // temporary workaround until new device policy is introduced (content for onblur or onmouse event will be added by javascript method)
                scriptWriter.write("Widget.addStartupItem(function(){Widget.getInstance(" + createJavaScriptString(validateAttributes.getId()) + ").setInputEvents()})");

                // Flush JavaScript to the page.
                writeJavaScript(currentBuffer, scriptWriter.toString());
            } catch (IOException e) {
                throw new ProtocolException(e);
            }

            // Close script element.
            closeScriptElement(currentBuffer);           
           
            // Register this validator widget in the possible enclosing wizard
            // widget.
            WidgetDefaultModule widgetModule =
                (WidgetDefaultModule) protocol.getWidgetModule();

            WizardDefaultRenderer wizardRenderer =
                (WizardDefaultRenderer) widgetModule.getWizardRenderer();

            if (wizardRenderer != null) {
                wizardRenderer.renderRegisterSimpleValidator(protocol, validateAttributes.getId());
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.protocols.widgets.attributes.ValidateAttributes

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.