Search in sources :

Example 36 with SystemException

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");
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) AbstractWFieldIndicator(com.github.bordertech.wcomponents.validation.AbstractWFieldIndicator) Input(com.github.bordertech.wcomponents.Input) SystemException(com.github.bordertech.wcomponents.util.SystemException) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Diagnosable(com.github.bordertech.wcomponents.Diagnosable)

Example 37 with SystemException

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);
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) FileWidgetUpload(com.github.bordertech.wcomponents.WMultiFileWidget.FileWidgetUpload)

Example 38 with SystemException

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();
        }
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 39 with SystemException

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);
    }
}
Also used : Field(java.lang.reflect.Field) SystemException(com.github.bordertech.wcomponents.util.SystemException) Templates(javax.xml.transform.Templates) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 40 with SystemException

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));
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) Test(org.junit.Test)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)94 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)13 Test (org.junit.Test)12 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 WebElement (org.openqa.selenium.WebElement)9 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)4 Request (com.github.bordertech.wcomponents.Request)4 InputStream (java.io.InputStream)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 Environment (com.github.bordertech.wcomponents.Environment)3 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Date (java.util.Date)3 List (java.util.List)3