/** * A convenience method to create an AJAX operation. * * @param target the component to target */ private void setActiveAjaxOperation(final WComponent target) { AjaxOperation operation = new AjaxOperation(target.getId(), target.getId()); AjaxHelper.setCurrentOperationDetails(operation, new ComponentWithContext(target, UIContextHolder.getCurrent())); } }
AjaxHelper.setCurrentOperationDetails(ajaxOperation, trigger);
AjaxHelper.setCurrentOperationDetails(operation, null);
AjaxHelper.setCurrentOperationDetails(new AjaxOperation("X", "Z"), null); AjaxHelper.setCurrentOperationDetails(new AjaxOperation(link.getId(), link.getId()), null);
AjaxHelper.setCurrentOperationDetails(operation, null); assertSchemaMatch(field); assertXpathExists("//ui:suggestions/ui:suggestion", field);
try { AjaxHelper.setCurrentOperationDetails(new AjaxOperation("testid", "X"), null); tab.preparePaintComponent(request); Assert.assertTrue("content should be visible", component.isVisible()); try { AjaxHelper.setCurrentOperationDetails(new AjaxOperation(tab.getId(), "X"), null); tab.preparePaintComponent(request); Assert.assertTrue("content should have been set to visible", component.isVisible());
@Test public void testHandleRequest() { TestAction action = new TestAction(); WMenu menu = new WMenu(); WSubMenu subMenu = new WSubMenu(TEST_TEXT); subMenu.setAction(action); menu.add(subMenu); setActiveContext(createUIContext()); // Menu not in Request MockRequest request = new MockRequest(); menu.serviceRequest(request); Assert.assertFalse("Action should not have been called when sub-menu was not invoked", action.wasTriggered()); // Menu in Request but submenu not current AJAX Trigger request = new MockRequest(); request.setParameter(menu.getId() + "-h", "x"); menu.serviceRequest(request); Assert.assertFalse("Action should not have been called when sub-menu was not invoked", action.wasTriggered()); // Menu in Request and submenu is the current ajax triiger request = new MockRequest(); request.setParameter(menu.getId() + "-h", "x"); request.setParameter(subMenu.getId(), "x"); try { // Setup AJAX Operation trigger by the submenu AjaxHelper.setCurrentOperationDetails(new AjaxOperation(subMenu.getId(), subMenu.getId()), null); menu.serviceRequest(request); } finally { AjaxHelper.clearCurrentOperationDetails(); } Assert.assertTrue("Action should have been called when sub-menu is invoked", action.wasTriggered()); }
/** * Test tab in tab group. */ @Test public void testTabInTabGroup() { WTabSet tabSet = new WTabSet(); WTabGroup group = new WTabGroup("Group"); WTab tab = new WTab(new WText("test in group"), "label", WTabSet.TabMode.DYNAMIC); tabSet.add(group); group.add(tab); setActiveContext(createUIContext()); // AJAX request but not for this WTab (Eager should be visible) MockRequest request = new MockRequest(); try { // Setup an AJAX operation that is not for this WTab AjaxHelper.setCurrentOperationDetails(new AjaxOperation(tab.getId(), "X"), null); tab.handleRequest(request); tab.preparePaintComponent(request); } finally { AjaxHelper.clearCurrentOperationDetails(); } }
@Test public void testRenderedEagerMode() throws IOException, SAXException, XpathException { WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING); figure.setMode(FigureMode.EAGER); UIContext uic = createUIContext(); uic.setUI(new DefaultWComponent()); setActiveContext(uic); // The figure's content should NOT be rendered assertSchemaMatch(figure); assertXpathEvaluatesTo("", "//ui:figure/@type", figure); assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure); assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure); assertXpathEvaluatesTo("", "//ui:figure/ui:content", figure); try { // Figure is the AJAX Trigger, content should be rendered AjaxOperation operation = new AjaxOperation(figure.getId(), figure.getId()); AjaxHelper.setCurrentOperationDetails(operation, null); assertSchemaMatch(figure); assertXpathEvaluatesTo("", "//ui:figure/@type", figure); assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure); assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure); assertXpathEvaluatesTo(FIGURE_CONTENT, "//ui:figure/ui:content", figure); } finally { AjaxHelper.clearCurrentOperationDetails(); } }
@Test public void testRenderedEagerModePanel() throws IOException, SAXException, XpathException { String content = "TEST CONTENT"; WPanel panel = new WPanel(); panel.setMode(PanelMode.EAGER); panel.add(new WText(content)); UIContext uic = createUIContext(); uic.setUI(new DefaultWComponent()); setActiveContext(uic); // The panel's content should NOT be rendered assertSchemaMatch(panel); assertXpathEvaluatesTo("", "//ui:panel/@type", panel); assertXpathEvaluatesTo("", "//ui:panel/@hidden", panel); assertXpathEvaluatesTo("eager", "//ui:panel/@mode", panel); assertXpathEvaluatesTo("", "//ui:panel/ui:content", panel); try { // Panel is the AJAX Trigger, content should be rendered AjaxOperation operation = new AjaxOperation(panel.getId(), panel.getId()); AjaxHelper.setCurrentOperationDetails(operation, null); assertSchemaMatch(panel); assertXpathEvaluatesTo("", "//ui:panel/@type", panel); assertXpathEvaluatesTo("", "//ui:panel/@hidden", panel); assertXpathEvaluatesTo("eager", "//ui:panel/@mode", panel); assertXpathEvaluatesTo(content, "//ui:panel/ui:content", panel); } finally { AjaxHelper.clearCurrentOperationDetails(); } }
@Test public void testRenderedEagerMode() throws IOException, SAXException, XpathException { WSection section = new WSection(SECTION_HEADING); section.setMode(SectionMode.EAGER); section.getContent().add(new WText(SECTION_CONTENT)); UIContext uic = createUIContext(); uic.setUI(new DefaultWComponent()); setActiveContext(uic); // The section's content should NOT be rendered assertSchemaMatch(section); assertXpathEvaluatesTo("", "//ui:section/@type", section); assertXpathEvaluatesTo("", "//ui:section/@hidden", section); assertXpathEvaluatesTo("eager", "//ui:section/@mode", section); assertXpathEvaluatesTo("", "normalize-space(//ui:section/ui:panel)", section); try { // Section is the AJAX Trigger, content should be rendered AjaxOperation operation = new AjaxOperation(section.getId(), section.getId()); AjaxHelper.setCurrentOperationDetails(operation, null); assertSchemaMatch(section); assertXpathEvaluatesTo("", "//ui:section/@type", section); assertXpathEvaluatesTo("", "//ui:section/@hidden", section); assertXpathEvaluatesTo("eager", "//ui:section/@mode", section); assertXpathEvaluatesTo(SECTION_CONTENT, "normalize-space(//ui:section/ui:panel)", section); } finally { AjaxHelper.clearCurrentOperationDetails(); } }