Search in sources :

Example 6 with WPartialDateField

use of com.github.bordertech.wcomponents.WPartialDateField in project wcomponents by BorderTech.

the class WPartialDateFieldRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WPartialDateField dateField = new WPartialDateField();
    dateField.setData(getMaliciousContent());
    try {
        assertSafeContent(dateField);
        Assert.fail("Invalid date should not have been parsed.");
    } catch (SystemException e) {
        Assert.assertNotNull("Exception has no message", e.getMessage());
    }
    dateField.setData(null);
    dateField.setToolTip(getMaliciousAttribute("ui:datefield"));
    assertSafeContent(dateField);
    dateField.setAccessibleText(getMaliciousAttribute("ui:datefield"));
    assertSafeContent(dateField);
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField) Test(org.junit.Test)

Example 7 with WPartialDateField

use of com.github.bordertech.wcomponents.WPartialDateField in project wcomponents by BorderTech.

the class WPartialDateFieldRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WPartialDateField component = new WPartialDateField();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WPartialDateFieldRenderer);
}
Also used : WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField) Test(org.junit.Test)

Example 8 with WPartialDateField

use of com.github.bordertech.wcomponents.WPartialDateField in project wcomponents by BorderTech.

the class WPartialDateFieldRenderer_Test method testReadOnly.

@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
    WPartialDateField dateField = new WPartialDateField();
    dateField.setReadOnly(true);
    assertSchemaMatch(dateField);
    assertXpathEvaluatesTo("true", "//ui:datefield/@readOnly", dateField);
}
Also used : WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField) Test(org.junit.Test)

Example 9 with WPartialDateField

use of com.github.bordertech.wcomponents.WPartialDateField in project wcomponents by BorderTech.

the class WPartialDateFieldRenderer method doRender.

/**
 * Paints the given WPartialDateField.
 *
 * @param component the WPartialDateField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPartialDateField dateField = (WPartialDateField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = dateField.isReadOnly();
    String date = formatDate(dateField);
    xml.appendTagOpen("ui:datefield");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", dateField.isHidden(), "true");
    xml.appendOptionalAttribute("date", date);
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendAttribute("allowPartial", "true");
        xml.appendOptionalAttribute("disabled", dateField.isDisabled(), "true");
        xml.appendOptionalAttribute("required", dateField.isMandatory(), "true");
        xml.appendOptionalAttribute("toolTip", dateField.getToolTip());
        xml.appendOptionalAttribute("accessibleText", dateField.getAccessibleText());
        WComponent submitControl = dateField.getDefaultSubmitButton();
        String submitControlId = submitControl == null ? null : submitControl.getId();
        xml.appendOptionalAttribute("buttonId", submitControlId);
    }
    xml.appendClose();
    if (date == null) {
        xml.appendEscaped(dateField.getText());
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(dateField, renderContext);
    }
    xml.appendEndTag("ui:datefield");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField)

Aggregations

WPartialDateField (com.github.bordertech.wcomponents.WPartialDateField)9 Test (org.junit.Test)7 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 WButton (com.github.bordertech.wcomponents.WButton)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WDateField (com.github.bordertech.wcomponents.WDateField)1 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WEmailField (com.github.bordertech.wcomponents.WEmailField)1 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)1 WMultiSelectPair (com.github.bordertech.wcomponents.WMultiSelectPair)1 WNumberField (com.github.bordertech.wcomponents.WNumberField)1 WPasswordField (com.github.bordertech.wcomponents.WPasswordField)1 WPhoneNumberField (com.github.bordertech.wcomponents.WPhoneNumberField)1 WRadioButton (com.github.bordertech.wcomponents.WRadioButton)1