Search in sources :

Example 1 with WValidationErrors

use of com.github.bordertech.wcomponents.validation.WValidationErrors in project wcomponents by BorderTech.

the class WValidationErrorsRenderer method doRender.

/**
 * Paints the given {@link WValidationErrors} component.
 *
 * @param component The {@link WValidationErrors} component to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WValidationErrors errors = (WValidationErrors) component;
    XmlStringBuilder xml = renderContext.getWriter();
    if (errors.hasErrors()) {
        xml.appendTagOpen("ui:validationerrors");
        xml.appendAttribute("id", component.getId());
        xml.appendOptionalAttribute("class", component.getHtmlClass());
        xml.appendOptionalAttribute("track", component.isTracking(), "true");
        xml.appendOptionalAttribute("title", errors.getTitleText());
        xml.appendClose();
        for (GroupedDiagnositcs nextGroup : errors.getGroupedErrors()) {
            // Render each diagnostic message in this group.
            for (Diagnostic nextMessage : nextGroup.getDiagnostics()) {
                xml.appendTagOpen("ui:error");
                WComponent forComponent = nextMessage.getComponent();
                if (forComponent != null) {
                    UIContextHolder.pushContext(nextMessage.getContext());
                    try {
                        xml.appendAttribute("for", forComponent.getId());
                    } finally {
                        UIContextHolder.popContext();
                    }
                }
                xml.appendClose();
                // of a WComponent as the message.
                if (nextMessage instanceof DiagnosticImpl) {
                    WComponent messageComponent = ((DiagnosticImpl) nextMessage).createDiagnosticErrorComponent();
                    // We add the component to a throw-away container so that it renders with the correct ID.
                    WContainer container = new WContainer() {

                        @Override
                        public String getId() {
                            return component.getId();
                        }
                    };
                    container.add(messageComponent);
                    messageComponent.paint(renderContext);
                    container.remove(messageComponent);
                    container.reset();
                } else {
                    xml.append(nextMessage.getDescription());
                }
                xml.appendEndTag("ui:error");
            }
        }
        xml.appendEndTag("ui:validationerrors");
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) GroupedDiagnositcs(com.github.bordertech.wcomponents.validation.WValidationErrors.GroupedDiagnositcs) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 2 with WValidationErrors

use of com.github.bordertech.wcomponents.validation.WValidationErrors in project wcomponents by BorderTech.

the class WValidationErrorsRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WValidationErrors errors = new WValidationErrors();
    String content = getMaliciousContent();
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, new DefaultWComponent(), content));
    errors.setErrors(diags);
    assertSafeContent(errors);
}
Also used : DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 3 with WValidationErrors

use of com.github.bordertech.wcomponents.validation.WValidationErrors in project wcomponents by BorderTech.

the class WButtonRenderer_Test method testAllOptions.

@Test
public void testAllOptions() throws IOException, SAXException, XpathException {
    WButton button = new WButton("All");
    button.setDisabled(true);
    setFlag(button, ComponentModel.HIDE_FLAG, true);
    button.setToolTip("Title");
    button.setAccessKey('T');
    button.setImageUrl("http://localhost/image.png");
    button.setImagePosition(ImagePosition.EAST);
    button.setRenderAsLink(true);
    button.setAjaxTarget(new WTextField());
    button.setPopupTrigger(true);
    setActiveContext(createUIContext());
    WPanel validationComponent = new WPanel();
    button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // Do nothing
        }
    });
    WContainer root = new WContainer();
    root.add(button);
    root.add(validationComponent);
    assertXpathExists("//html:button[@id]", button);
    assertXpathExists("//html:button[contains(@class, 'wc-linkbutton')]", button);
    assertXpathEvaluatesTo(button.getText(), "//html:button", button);
    assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button);
    assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button);
    assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button);
    assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button);
    assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button);
    assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button);
    assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button);
    assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button);
    button.setImagePosition(ImagePosition.NORTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgn')]", button);
    button.setImagePosition(ImagePosition.SOUTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgs')]", button);
    button.setImagePosition(ImagePosition.WEST);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgw')]", button);
    button.setClientCommandOnly(true);
    assertXpathEvaluatesTo("button", "//html:button/@type", button);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) WButton(com.github.bordertech.wcomponents.WButton) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 4 with WValidationErrors

use of com.github.bordertech.wcomponents.validation.WValidationErrors in project wcomponents by BorderTech.

the class AllComponents method addComponents.

/**
 * Adds the components to the container.
 */
private void addComponents() {
    add(new DefaultTransientDataContainer(new WText("Transient data container content")));
    add(new DefaultWComponent());
    add(createRadioButtonGroup());
    add(new WAbbrText());
    add(createAjaxControl());
    add(new WAjaxPollingRegion(123));
    add(new WAudio());
    add(new WBeanContainer());
    add(new WButton("Button text"));
    add(new WCancelButton());
    add(new WCardManager());
    add(new WCheckBox());
    add(new WCheckBoxSelect(new String[] { "a", "b", "c", "d" }));
    add(new WCollapsible(new WText("Collapsible content"), "Collapsible heading"));
    add(new WCollapsibleToggle());
    add(new WColumnLayout("Column layout heading"));
    add(new WConfirmationButton("Confirmation button"));
    add(new WContainer());
    add(new WContent());
    add(createSampleWContentLink());
    add(new WDateField());
    add(new WDecoratedLabel("Decorated label text"));
    add(new WDefinitionList());
    add(new WDialog(new WText("Dialog content")));
    add(new WDropdown(new String[] { "a", "b", "c", "d" }));
    add(new WEmailField());
    add(createFieldLayout());
    add(new WFieldSet("Field set title"));
    add(new WFileWidget());
    add(new WFilterText("search", "replace"));
    add(new WHeading(HeadingLevel.H3, "WHeading title"));
    add(new WHorizontalRule());
    add(new WImage("/image/x1.gif", "example image"));
    add(new WInternalLink("Internal link text", this));
    add(new WInvisibleContainer());
    add(new WLabel("Label text"));
    add(new WLink("link text", "http://localhost"));
    add(createSampleWList());
    add(createMenu());
    add(new WMessageBox(WMessageBox.INFO, "WMessageBox message"));
    add(new WMessages());
    add(new WMultiDropdown(new String[] { "a", "b", "c", "d" }));
    add(new WMultiFileWidget());
    add(new WMultiSelect(new String[] { "a", "b", "c", "d" }));
    add(new WMultiSelectPair(new String[] { "a", "b", "c", "d" }));
    add(new WMultiTextField(new String[] { "a", "b", "c", "d" }));
    add(new WNumberField());
    add(new WPanel());
    add(new WPartialDateField());
    add(new WPasswordField());
    add(new WPhoneNumberField());
    add(new WPopup());
    add(new WPrintButton("Print button text"));
    add(new WProgressBar(100));
    add(new WRadioButtonSelect(new String[] { "a", "b", "c", "d" }));
    add(new WRepeater(new WText()));
    add(createWRow());
    add(new WSelectToggle(false, this));
    add(new WSeparator());
    add(new WShuffler(Arrays.asList("a", "b", "c", "d")));
    add(new WSingleSelect(new String[] { "a", "b", "c", "d" }));
    add(new WSkipLinks());
    add(new WStyledText("styled text", WStyledText.Type.EMPHASISED));
    add(new WSubordinateControl());
    add(new WSuggestions(Arrays.asList("a", "b", "c", "d")));
    add(createTabSet());
    add(createWTable());
    add(new WText("text"));
    add(new WTextArea());
    add(new WTextField());
    add(new WValidationErrors());
    add(new WVideo());
    add(new WWindow());
}
Also used : WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors)

Example 5 with WValidationErrors

use of com.github.bordertech.wcomponents.validation.WValidationErrors in project wcomponents by BorderTech.

the class WValidationErrorsRenderer_Test method testRendererCorrectlyConfigured.

/**
 * Test the Layout is correctly configured.
 */
@Test
public void testRendererCorrectlyConfigured() {
    WValidationErrors errors = new WValidationErrors();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(errors) instanceof WValidationErrorsRenderer);
}
Also used : WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) Test(org.junit.Test)

Aggregations

WValidationErrors (com.github.bordertech.wcomponents.validation.WValidationErrors)6 Test (org.junit.Test)4 WContainer (com.github.bordertech.wcomponents.WContainer)3 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)3 DiagnosticImpl (com.github.bordertech.wcomponents.validation.DiagnosticImpl)3 ArrayList (java.util.ArrayList)2 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)1 WButton (com.github.bordertech.wcomponents.WButton)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WPanel (com.github.bordertech.wcomponents.WPanel)1 WTextArea (com.github.bordertech.wcomponents.WTextArea)1 WTextField (com.github.bordertech.wcomponents.WTextField)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)1 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)1 GroupedDiagnositcs (com.github.bordertech.wcomponents.validation.WValidationErrors.GroupedDiagnositcs)1