use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class DateFieldPivotValidator_Test method runTest.
/**
* @param operator the date operator
* @return the test results
*/
private String[][] runTest(final int operator) {
String[][] result = new String[DATES.length][DATES[0].length];
for (int run = 0; run < DATES.length; run++) {
DateFieldPivotValidator validator = new DateFieldPivotValidator(operator);
validator.setFixedPivot(DATES[run][2]);
WDateField dateField = new WDateField();
dateField.addValidator(validator);
List<Diagnostic> diags = new ArrayList<>();
for (int i = 0; i < DATES[run].length; i++) {
diags.clear();
dateField.setDate(DATES[run][i]);
dateField.validate(diags);
Assert.assertTrue("Should only have a maximum of 1 error", diags.size() < 2);
if (!diags.isEmpty()) {
result[run][i] = (diags.get(0)).getDescription();
}
}
}
return result;
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class Validation_Test method testMandatory.
@Test
public void testMandatory() {
List<Diagnostic> diags = new ArrayList<>();
WTextField textField = new WTextField();
Assert.assertFalse("Text field should not be mandatory by default", textField.isMandatory());
// No validation logic yet, but that should still be ok.
textField.validate(diags);
Assert.assertEquals("Diags should be empty when there are no validators", 0, diags.size());
// Add a mandatory validation
textField.setMandatory(true);
Assert.assertTrue("Text field should be mandatory", textField.isMandatory());
textField.validate(diags);
Assert.assertEquals("Diags should contain mandatory validation error", 1, diags.size());
// Add some text to the text field
textField.setText("Blah");
diags.clear();
textField.validate(diags);
Assert.assertEquals("Diags should be empty when mandatory field is filled in", 0, diags.size());
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class DiagnosticRenderUtil method renderHelper.
/**
* Render the diagnostics.
* @param renderContext the current renderContext
* @param diags the list of Diagnostic objects
* @param severity the severity we are rendering
*/
private static void renderHelper(final WebXmlRenderContext renderContext, final List<Diagnostic> diags, final int severity) {
if (diags.isEmpty()) {
return;
}
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen(TAG_NAME);
xml.appendAttribute("type", getLevel(severity));
xml.appendClose();
for (Diagnostic diagnostic : diags) {
xml.appendTag(MESSAGE_TAG_NAME);
xml.appendEscaped(diagnostic.getDescription());
xml.appendEndTag(MESSAGE_TAG_NAME);
}
xml.appendEndTag(TAG_NAME);
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class WFileWidgetRenderer method doRender.
/**
* Paints the given WFileWidget.
*
* @param component the WFileWidget to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WFileWidget fileWidget = (WFileWidget) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = fileWidget.isReadOnly();
xml.appendTagOpen(TAG_NAME);
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
xml.appendEnd();
return;
}
xml.appendOptionalAttribute("disabled", fileWidget.isDisabled(), "true");
xml.appendOptionalAttribute("required", fileWidget.isMandatory(), "true");
xml.appendOptionalAttribute("toolTip", fileWidget.getToolTip());
xml.appendOptionalAttribute("accessibleText", fileWidget.getAccessibleText());
xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(fileWidget.getFileTypes()));
long maxFileSize = fileWidget.getMaxFileSize();
xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
List<Diagnostic> diags = fileWidget.getDiagnostics(Diagnostic.ERROR);
if (diags == null || diags.isEmpty()) {
xml.appendEnd();
return;
}
xml.appendClose();
DiagnosticRenderUtil.renderDiagnostics(fileWidget, renderContext);
xml.appendEndTag(TAG_NAME);
}
use of com.github.bordertech.wcomponents.validation.Diagnostic in project wcomponents by BorderTech.
the class WMultiFileWidgetRenderer method doRender.
/**
* Paints the given WMultiFileWidget.
*
* @param component the WMultiFileWidget to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WMultiFileWidget widget = (WMultiFileWidget) component;
XmlStringBuilder xml = renderContext.getWriter();
// Check if rendering a file upload response
String uploadId = widget.getFileUploadRequestId();
if (uploadId != null) {
handleFileUploadRequest(widget, xml, uploadId);
return;
}
boolean readOnly = widget.isReadOnly();
xml.appendTagOpen(TAG_NAME);
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", widget.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
long maxFileSize = widget.getMaxFileSize();
int maxFiles = widget.getMaxFiles();
WComponent dropzone = widget.getDropzone();
WImageEditor editor = widget.getEditor();
xml.appendOptionalAttribute("disabled", widget.isDisabled(), "true");
xml.appendOptionalAttribute("required", widget.isMandatory(), "true");
xml.appendOptionalAttribute("toolTip", widget.getToolTip());
xml.appendOptionalAttribute("accessibleText", widget.getAccessibleText());
xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(widget.getFileTypes()));
xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
xml.appendOptionalAttribute("maxFiles", maxFiles > 0, maxFiles);
if (dropzone != null) {
xml.appendAttribute("dropzone", dropzone.getId());
}
if (editor != null) {
xml.appendAttribute("editor", editor.getId());
if (editor.getUseCamera()) {
xml.appendAttribute("camera", true);
}
}
}
if (widget.getColumns() != null) {
xml.appendAttribute("cols", widget.getColumns());
}
if (widget.getFileAjaxAction() != null) {
xml.appendAttribute("ajax", "true");
}
List<Diagnostic> diags = readOnly ? null : widget.getDiagnostics(Diagnostic.ERROR);
if (widget.getFiles().isEmpty()) {
if (readOnly || diags == null || diags.isEmpty()) {
xml.appendEnd();
return;
}
xml.appendClose();
} else {
xml.appendClose();
// Render files
int i = 0;
for (FileWidgetUpload file : widget.getFiles()) {
FileWidgetRendererUtil.renderFileElement(widget, xml, file, i++);
}
}
if (!readOnly && diags != null && !diags.isEmpty()) {
DiagnosticRenderUtil.renderDiagnostics(widget, renderContext);
}
xml.appendEndTag(TAG_NAME);
}
Aggregations