use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class AbstractWFieldIndicatorRenderer method doRender.
/**
* Paints the given AbstractWFieldIndicator.
*
* @param component the WFieldErrorIndicator to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
AbstractWFieldIndicator fieldIndicator = (AbstractWFieldIndicator) component;
XmlStringBuilder xml = renderContext.getWriter();
WComponent validationTarget = fieldIndicator.getTargetComponent();
// Diagnosables takes care of thieir own messaging.
if (validationTarget == null || (validationTarget instanceof Diagnosable && !(validationTarget instanceof Input))) {
return;
}
if (validationTarget instanceof Input && !((Input) validationTarget).isReadOnly()) {
return;
}
List<Diagnostic> diags = fieldIndicator.getDiagnostics();
if (diags != null && !diags.isEmpty()) {
xml.appendTagOpen("ui:fieldindicator");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
switch(fieldIndicator.getFieldIndicatorType()) {
case INFO:
xml.appendAttribute("type", "info");
break;
case WARN:
xml.appendAttribute("type", "warn");
break;
case ERROR:
xml.appendAttribute("type", "error");
break;
default:
throw new SystemException("Cannot paint field indicator due to an invalid field indicator type: " + fieldIndicator.getFieldIndicatorType());
}
xml.appendAttribute("for", fieldIndicator.getRelatedFieldId());
xml.appendClose();
for (Diagnostic diag : diags) {
xml.appendTag("ui:message");
xml.appendEscaped(diag.getDescription());
xml.appendEndTag("ui:message");
}
xml.appendEndTag("ui:fieldindicator");
}
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class WCheckBoxRenderer method doRender.
/**
* Paints the given WCheckBox.
*
* @param component the WCheckBox to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WCheckBox checkBox = (WCheckBox) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = checkBox.isReadOnly();
xml.appendTagOpen(TAG_NAME);
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", checkBox.isHidden(), "true");
xml.appendOptionalAttribute("selected", checkBox.isSelected(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
xml.appendEnd();
return;
}
WComponent submitControl = checkBox.getDefaultSubmitButton();
String submitControlId = submitControl == null ? null : submitControl.getId();
WComponentGroup<WCheckBox> group = checkBox.getGroup();
String groupName = group == null ? null : group.getId();
xml.appendOptionalAttribute("groupName", groupName);
xml.appendOptionalAttribute("disabled", checkBox.isDisabled(), "true");
xml.appendOptionalAttribute("required", checkBox.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", checkBox.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", checkBox.getToolTip());
xml.appendOptionalAttribute("accessibleText", checkBox.getAccessibleText());
xml.appendOptionalAttribute("buttonId", submitControlId);
List<Diagnostic> diags = checkBox.getDiagnostics(Diagnostic.ERROR);
if (diags == null || diags.isEmpty()) {
xml.appendEnd();
return;
}
xml.appendClose();
DiagnosticRenderUtil.renderDiagnostics(checkBox, renderContext);
xml.appendEndTag(TAG_NAME);
}
use of com.github.bordertech.wcomponents.validation.Diagnostic 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);
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class WFieldErrorIndicatorRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WContainer root = new WContainer();
WPanel target = new WPanel();
WFieldErrorIndicator indicator = new WFieldErrorIndicator(target);
root.add(indicator);
root.add(target);
List<Diagnostic> diags = new ArrayList<>();
diags.add(new DiagnosticImpl(Diagnostic.ERROR, target, getMaliciousContent()));
root.showErrorIndicators(diags);
assertSafeContent(root);
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class WFieldWarningIndicatorRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
WContainer root = new WContainer();
WPanel target = new WPanel();
WFieldWarningIndicator indicator = new WFieldWarningIndicator(target);
root.add(target);
root.add(indicator);
// Simulate Warning Message
setActiveContext(createUIContext());
List<Diagnostic> diags = new ArrayList<>();
diags.add(new DiagnosticImpl(Diagnostic.WARNING, target, "Test Warning"));
root.showWarningIndicators(diags);
// Validate Schema
assertSchemaMatch(root);
// Check Attributes
assertXpathEvaluatesTo(indicator.getId(), "//ui:fieldindicator/@id", root);
assertXpathEvaluatesTo("warn", "//ui:fieldindicator/@type", root);
assertXpathEvaluatesTo(target.getId(), "//ui:fieldindicator/@for", root);
// Check Message
assertXpathEvaluatesTo("Test Warning", "//ui:fieldindicator/ui:message", root);
}
Aggregations