/** * Creates a UIContextWrap. */ public UIContextWrap() { super(new UIContextImpl()); }
/** * Adds a runnable to the list of runnables to be invoked later. * * @param runnable the runnable to add */ @Override public void invokeLater(final Runnable runnable) { invokeLater(this, runnable); }
UIContextImpl uic1 = new UIContextImpl(); uic1.setEnvironment(new WServlet.WServletEnvironment("app", "http://localhost", "")); uic1.setUI(ui); uic1.getEnvironment().setSessionToken("1"); uic1.getEnvironment().setStep(1); UIContextImpl uic2 = new UIContextImpl(); uic2.setEnvironment(new WServlet.WServletEnvironment("app", "http://localhost", "")); uic2.setUI(ui); uic2.getEnvironment().setSessionToken("2");
@Test public void testUIContextSerialization() { MyApplication app = (MyApplication) UIRegistry.getInstance().getUI(MyApplication.class. getName()); UIContextImpl uic = new UIContextImpl(); setActiveContext(uic); uic.setUI(app); WTextField name = app.getText(); name.setText(TEST_STRING); Assert.assertEquals("Initial text incorrect", TEST_STRING, name.getText()); // Pipe the ui context uic = (UIContextImpl) pipe(uic); setActiveContext(uic); // Components returned should be the same instance MyApplication pipedApp = (MyApplication) uic.getUI(); Assert.assertSame("Should be the same component instance", app, pipedApp); Assert.assertSame("Should be the same text field instance", app.getText(), pipedApp. getText()); Assert.assertEquals("Text incorrect after serialization", TEST_STRING, name.getText()); }
/** * Obtains a UI Context. * * This is called by many of the other methods where a UIContext is not explicitly passed. Subclasses can therefore * e.g. override this to ensure that the same context is always used. * * @return a new UIContext. */ @Override protected UIContext createUIContext() { return new UIContextImpl(); }
/** * Creates a UI Context. * * @return a new UIContext. */ protected UIContext createUIContext() { UIContext uic = new UIContextImpl(); return uic; }
/** * Obtains a UI Context. * * This is called by many of the other methods where a UIContext is not explicitly passed. Subclasses can therefore * e.g. override this to ensure that the same context is always used. * * @return a new UIContext. */ protected UIContext createUIContext() { return new UIContextImpl(); } }
/** * Creates and initialises a new UIContext. * * @return a new UIContext. */ protected UIContext createUIContext() { // Create UIC UIContext uic = new UIContextImpl(); uic.setUI(getUI()); return uic; }
/** * Replaces the UIContext with a new copy, to emulate a fresh session. */ protected void resetUIContext() { uic = new UIContextImpl(); uic.setUI(getWrappedUi()); }
/** * Renders the given WComponent to a String outside of the context of a Servlet. This is good for getting hold of * the XML for debugging, unit testing etc. Also it is good for using the WComponent framework as a more generic * templating framework. * * @param request the request being responded to. * @param component the root WComponent to render. * @return the rendered output as a String. */ public static String render(final Request request, final WComponent component) { boolean needsContext = UIContextHolder.getCurrent() == null; if (needsContext) { UIContextHolder.pushContext(new UIContextImpl()); } try { StringWriter buffer = new StringWriter(); component.preparePaint(request); try (PrintWriter writer = new PrintWriter(buffer)) { component.paint(new WebXmlRenderContext(writer)); } return buffer.toString(); } finally { if (needsContext) { UIContextHolder.popContext(); } } }
UIContext uic = new UIContextImpl(); uic.setEnvironment(createEnvironment()); UIContextHolder.pushContext(uic); UIContextHolder.pushContext(new UIContextImpl()); try { html = WebUtilities.render(errorPage);
UIContextImpl uic = new UIContextImpl(); PrintWriter printWriter = new PrintWriter(new NullWriter()); RenderContext renderContext = new WebXmlRenderContext(printWriter);
@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()); } }
app.setLocked(true); UIContext uic = new UIContextImpl(); uic.setUI(app); setActiveContext(uic);
UIContextHolder.pushContext(new UIContextImpl());
@Test public void testCrtEntryExpiration() throws IOException, SAXException, XpathException { UIContext uic1 = new UIContextImpl(); UIContext uic2 = new UIContextImpl() { @Override public long getCreationTime() { return 0; // 01 jan 1970 - should have no options } }; // Test getOptions accessor WDropdown drop = new WDropdown(TestLookupTable.YesNoTable.class); // Test rendered format setActiveContext(uic1); assertSchemaMatch(drop); assertXpathEvaluatesTo("2", "count(//ui:dropdown/ui:option)", drop); setActiveContext(uic2); assertSchemaMatch(drop); assertXpathEvaluatesTo("0", "count(//ui:dropdown/ui:option)", drop); }
app.setLocked(true); UIContext uic = new UIContextImpl(); uic.setUI(app); setActiveContext(uic);
@Test public void testSetActionCommand() { String text = "WButton_Test.text"; String sharedValue = "WButton_Test.sharedValue"; String value = "WButton_Test.value"; UIContext uic1 = new UIContextImpl(); WButton button = new WButton(text); button.setLocked(true); Assert.assertEquals("Default action command should be button text", text, button. getActionCommand()); button.setActionCommand(sharedValue); Assert.assertEquals("Incorrect shared action command returned", sharedValue, button. getActionCommand()); setActiveContext(uic1); button.setActionCommand(value); Assert.assertEquals("Uic 1 action command should be returned for uic 1", value, button. getActionCommand()); Assert. assertFalse("Button should not be in default state for uic1", button. isDefaultState()); resetContext(); Assert.assertEquals("Incorrect shared action command returned", sharedValue, button. getActionCommand()); }
Assert.assertTrue("should be set as sorted", table.isSorted()); UIContext uic1 = new UIContextImpl(); UIContext uic2 = new UIContextImpl();
@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()); }