Search in sources :

Example 1 with UIContextImpl

use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.

the class AbstractContainerHelper method renderErrorPageToHTML.

/**
 * Render the error page component to HTML.
 *
 * @param errorPage the error page component
 * @return the error page as HTML
 */
protected String renderErrorPageToHTML(final WComponent errorPage) {
    // Check if using the default error page
    boolean defaultErrorPage = errorPage instanceof FatalErrorPage;
    String html = null;
    // If not default implementation of error page, Transform error page to HTML
    if (!defaultErrorPage) {
        // Set UIC and Environment (Needed for Theme Paths)
        UIContext uic = new UIContextImpl();
        uic.setEnvironment(createEnvironment());
        UIContextHolder.pushContext(uic);
        try {
            html = WebUtilities.renderWithTransformToHTML(errorPage);
        } catch (Exception e) {
            LOG.warn("Could not transform error page.", e);
        } finally {
            UIContextHolder.popContext();
        }
    }
    // Not transformed. So just render.
    if (html == null) {
        UIContextHolder.pushContext(new UIContextImpl());
        try {
            html = WebUtilities.render(errorPage);
        } catch (Exception e) {
            LOG.warn("Could not render error page.", e);
            html = "System error occurred but could not render error page.";
        } finally {
            UIContextHolder.popContext();
        }
    }
    return html;
}
Also used : FatalErrorPage(com.github.bordertech.wcomponents.FatalErrorPage) UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) IOException(java.io.IOException) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Example 2 with UIContextImpl

use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.

the class DevToolkit_Test method setUp.

@Before
public void setUp() {
    UIContext uic = new UIContextImpl();
    uic.setUI(new WText("dummy"));
    UIContextHolder.pushContext(uic);
    Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_TOOKIT, "true");
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) WText(com.github.bordertech.wcomponents.WText) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) Before(org.junit.Before)

Example 3 with UIContextImpl

use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.

the class TreeUtil_Test method initTree.

@Before
public void initTree() {
    root = new WApplication();
    containerChild = new WContainer();
    simpleChild = new WTextField();
    repeatedComponent = new WText();
    repeaterChild = new WRepeater(repeatedComponent);
    grandChild = new WTextArea();
    cardManager = new WCardManager();
    card1 = new WText();
    card2 = new WText();
    root.add(containerChild);
    root.add(simpleChild);
    root.add(repeaterChild);
    root.add(cardManager);
    containerChild.add(grandChild);
    cardManager.add(card1);
    cardManager.add(card2);
    root.setLocked(true);
    setActiveContext(new UIContextImpl());
    repeaterChild.setData(Arrays.asList(new String[] { "1", "2", "3" }));
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WContainer(com.github.bordertech.wcomponents.WContainer) WApplication(com.github.bordertech.wcomponents.WApplication) WText(com.github.bordertech.wcomponents.WText) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WCardManager(com.github.bordertech.wcomponents.WCardManager) WTextField(com.github.bordertech.wcomponents.WTextField) WRepeater(com.github.bordertech.wcomponents.WRepeater) Before(org.junit.Before)

Example 4 with UIContextImpl

use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.

the class DiagnosticImpl_Test method testGetContext.

@Test
public void testGetContext() {
    final UIContext uic = new UIContextImpl();
    DiagnosticImpl diag = new DiagnosticImpl(Diagnostic.INFO, uic, new WTextField(), "dummy");
    Assert.assertSame("Incorrect UI context", uic, diag.getContext());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 5 with UIContextImpl

use of com.github.bordertech.wcomponents.UIContextImpl in project wcomponents by BorderTech.

the class Validation_Test method testMandatorySpecificToUser.

@Test
public void testMandatorySpecificToUser() {
    UIContext uic1 = new UIContextImpl();
    UIContext uic2 = new UIContextImpl();
    List<Diagnostic> diags = new ArrayList<>();
    // uic 1 has mandatory check
    // uic 2 does not.
    WTextField textField = new WTextField();
    textField.setLocked(true);
    setActiveContext(uic1);
    textField.setMandatory(true);
    textField.validate(diags);
    Assert.assertEquals("UIC 1 should have a validation error", 1, diags.size());
    diags.clear();
    setActiveContext(uic2);
    textField.validate(diags);
    Assert.assertEquals("UIC 2 should not have a validation error", 0, diags.size());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)17 UIContext (com.github.bordertech.wcomponents.UIContext)11 Test (org.junit.Test)7 Before (org.junit.Before)6 WLabel (com.github.bordertech.wcomponents.WLabel)5 WTextField (com.github.bordertech.wcomponents.WTextField)4 PrintWriter (java.io.PrintWriter)4 WApplication (com.github.bordertech.wcomponents.WApplication)3 WButton (com.github.bordertech.wcomponents.WButton)3 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)2 RenderContext (com.github.bordertech.wcomponents.RenderContext)2 WText (com.github.bordertech.wcomponents.WText)2 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)2 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 FatalErrorPage (com.github.bordertech.wcomponents.FatalErrorPage)1 TestLookupTable (com.github.bordertech.wcomponents.TestLookupTable)1