use of com.github.bordertech.wcomponents.util.SystemException 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.util.SystemException in project wcomponents by BorderTech.
the class WMultiFileWidgetRenderer method handleFileUploadRequest.
/**
* Paint the response for the file uploaded in this request.
*
* @param widget the file widget to render
* @param xml the XML string builder
* @param uploadId the file id uploaded in this request
*/
protected void handleFileUploadRequest(final WMultiFileWidget widget, final XmlStringBuilder xml, final String uploadId) {
FileWidgetUpload file = widget.getFile(uploadId);
if (file == null) {
throw new SystemException("Invalid file id [" + uploadId + "] to render uploaded response.");
}
int idx = widget.getFiles().indexOf(file);
FileWidgetRendererUtil.renderFileElement(widget, xml, file, idx);
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class AjaxInterceptor method paintResponse.
/**
* Paint the ajax response.
*
* @param renderContext the render context
* @param operation the ajax operation
*/
private void paintResponse(final RenderContext renderContext, final AjaxOperation operation) {
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
XmlStringBuilder xml = webRenderContext.getWriter();
// Get trigger's context
ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
if (trigger == null) {
throw new SystemException("No context available for trigger " + operation.getTriggerId());
}
for (String targetId : operation.getTargets()) {
ComponentWithContext target;
if (targetId.equals(operation.getTriggerId())) {
target = trigger;
} else {
target = WebUtilities.getComponentById(targetId, true);
if (target == null) {
LOG.warn("Could not find ajax target to render [" + targetId + "]");
continue;
}
}
UIContextHolder.pushContext(target.getContext());
try {
xml.appendTagOpen("ui:ajaxtarget");
xml.appendAttribute("id", targetId);
xml.appendAttribute("action", operation.getAction().getDesc());
xml.appendClose();
target.getComponent().paint(renderContext);
xml.appendEndTag("ui:ajaxtarget");
} finally {
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class TransformXMLTestHelper method reloadTransformer.
/**
* Use reflection the reinitialize the TransformXMLInterceptor class.
*/
public static void reloadTransformer() {
try {
Field field = TransformXMLInterceptor.class.getDeclaredField("TEMPLATES");
// Make the field accessible.
field.setAccessible(true);
// Make the field non-final.
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
// Get the value from the static method
Method initTemplates = TransformXMLInterceptor.class.getDeclaredMethod("initTemplates");
initTemplates.setAccessible(true);
Templates value = (Templates) initTemplates.invoke(null);
field.set(null, value);
} catch (SecurityException | InvocationTargetException | NoSuchFieldException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException ex) {
throw new SystemException(ex);
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class AbstractContainerHelper_Test method testHandleErrorCustom.
@Test
public void testHandleErrorCustom() throws IOException {
MyContainerHelper helper = new MyContainerHelper();
SystemException error = new SystemException("custom");
helper.handleError(error);
String output = helper.stringWriter.toString();
Assert.assertTrue("Should contain transformed XML", output.contains(TransformXMLTestHelper.EXPECTED));
}
Aggregations