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);
}
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);
}
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);
}
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");
}
Aggregations