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;
}
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");
}
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" }));
}
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());
}
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());
}
Aggregations