/** * Registers one or more components as being AJAX capable. * * @param targetIds the components to register. Each component will be re-painted when the trigger occurs. * @param triggerId the id of the trigger that will cause the components to be painted. * @return the AjaxOperation control configuration object. */ public static AjaxOperation registerComponents(final List<String> targetIds, final String triggerId) { AjaxOperation operation = new AjaxOperation(triggerId, targetIds); registerAjaxOperation(operation); return operation; }
/** * Registers a single component as being AJAX capable. * * @param targetId the component to register. The component will be re-painted when the trigger occurs. * @param triggerId the id of the trigger that will cause the component to be painted. * @return the AjaxOperation control configuration object. */ public static AjaxOperation registerComponent(final String targetId, final String triggerId) { AjaxOperation operation = new AjaxOperation(triggerId, targetId); registerAjaxOperation(operation); return operation; }
/** * This internal method is used to register an arbitrary target container. It must only used by components which * contain implicit AJAX capability. * * @param triggerId the id of the trigger that will cause the component to be painted. * @param containerId the target container id. This is not necessarily a WComponent id. * @param containerContentIds the container content. * @return the AjaxOperation control configuration object. */ static AjaxOperation registerContainer(final String triggerId, final String containerId, final List<String> containerContentIds) { AjaxOperation operation = new AjaxOperation(triggerId, containerContentIds); operation.setTargetContainerId(containerId); operation.setAction(AjaxOperation.AjaxAction.REPLACE_CONTENT); registerAjaxOperation(operation); return operation; }
/** * This internal method is used to register an arbitrary target container. It must only used by components which * contain implicit AJAX capability. * * @param triggerId the id of the trigger that will cause the component to be painted. * @param containerId the target container id. This is not necessarily a WComponent id. * @param containerContentId the container content. * @return the AjaxOperation control configuration object. */ static AjaxOperation registerContainer(final String triggerId, final String containerId, final String containerContentId) { AjaxOperation operation = new AjaxOperation(triggerId, containerContentId); operation.setTargetContainerId(containerId); operation.setAction(AjaxOperation.AjaxAction.REPLACE_CONTENT); registerAjaxOperation(operation); return operation; }
ajaxOperation = new AjaxOperation(triggerId); } else { ajaxOperation = new AjaxOperation(triggerId); ajaxOperation = new AjaxOperation(triggerId);
/** * 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())); } }
AjaxOperation operation = new AjaxOperation(sugg.getId(), sugg.getId()); AjaxHelper.setCurrentOperationDetails(operation, null);
AjaxHelper.setCurrentOperationDetails(new AjaxOperation("X", "Z"), null); AjaxHelper.setCurrentOperationDetails(new AjaxOperation(link.getId(), link.getId()), null);
AjaxOperation operation = new AjaxOperation(field.getId(), field.getId()); AjaxHelper.setCurrentOperationDetails(operation, null); assertSchemaMatch(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(); } }