/** * Creates a ByWComponentPath which searches for a path to a component. * * @param componentWithContext the component to search for. * @param path the path to traverse. */ public ByWComponentPath(final ComponentWithContext componentWithContext, final String path) { this(componentWithContext.getComponent(), componentWithContext.getContext(), path); }
/** * Creates a ByWComponent which searches for a component instance in the given context. If searching for a repeated * component, the <code>context</code> should be the row context for the row you want to return. * * @param componentWithContext the component to search for. */ public ByWComponent(final ComponentWithContext componentWithContext) { this(componentWithContext.getComponent(), componentWithContext.getContext(), null); }
/** * Creates a ByWComponentPath which searches for a path to a component. * * @param componentWithContext the component to search for. * @param path the path to traverse. * @param visibleOnly only look for components that are visible */ public ByWComponentPath(final ComponentWithContext componentWithContext, final String path, final boolean visibleOnly) { this(componentWithContext.getComponent(), componentWithContext.getContext(), path, visibleOnly); }
/** * Retrieves the context for the component with the given Id. * * @param root the root component to search from. * @param id the id to search for. * @param visibleOnly true if process visible only * @return the context for the component with the given id, or null if not found. */ public static UIContext getContextForId(final WComponent root, final String id, final boolean visibleOnly) { ComponentWithContext comp = getComponentWithContextForId(root, id, visibleOnly); return comp == null ? null : comp.getContext(); }
/** * Indicates whether the list contains the given component and context. * * @param components the list of components to check. * @param component the component to search for. * @param uic the component context to search for. * @return true if the component is in the list with the given context, false otherwise. */ private boolean isInList(final List<ComponentWithContext> components, final WComponent component, final UIContext uic) { for (ComponentWithContext comp : components) { if (comp.getComponent() == component && comp.getContext() == uic) { return true; } } return false; }
/** * Override getStep to retrieve the step from a WWindow if the targeted component is a WWindow or a descendant * of one. * * @return the step count. */ @Override public int getStep() { // WWindows require a special case, as they keep track of their own separate step. // We must check if the request is an AJAX or content target inside a WWindow, // and if so return that WWindow's step. Otherwise, we return the step on the // environment. UIContextHolder.pushContext(window.getContext()); try { WWindow targetWindow = (WWindow) window.getComponent(); return targetWindow.getStep(); } finally { UIContextHolder.popContext(); } }
/** * Override setStep to store the step on a WWindow if the targeted component is a WWindow or a descendant of * one. * * @param step the step count to set. */ @Override public void setStep(final int step) { // WWindows require a special case, as they keep track of their own separate step. // We must check if the request is an AJAX or content target inside a WWindow, // and if so set that WWindow's step. Otherwise, we set the step on the // environment. UIContextHolder.pushContext(window.getContext()); try { WWindow targetWindow = (WWindow) window.getComponent(); targetWindow.setStep(step); } finally { UIContextHolder.popContext(); } } }
/** * {@inheritDoc} */ @Override public void paint(final RenderContext renderContext) { ComponentWithContext target = WebUtilities.getComponentById(targetId, true); if (target == null) { throw new SystemException("No target component found for id " + targetId); } UIContextHolder.pushContext(target.getContext()); try { super.paint(renderContext); } finally { UIContextHolder.popContext(); } }
/** * {@inheritDoc} */ @Override public void preparePaint(final Request request) { ComponentWithContext target = WebUtilities.getComponentById(targetId, true); if (target == null) { throw new SystemException("No target component found for id " + targetId); } UIContextHolder.pushContext(target.getContext()); try { super.preparePaint(request); } finally { UIContextHolder.popContext(); } }
/** * Retrieves the closest context for the component with the given Id. * * @param root the root component to search from. * @param id the id to search for. * @param visibleOnly true if process visible only * @return the closest context for the component with the given id, or null if not found. */ public static UIContext getClosestContextForId(final WComponent root, final String id, final boolean visibleOnly) { FindComponentByIdVisitor visitor = new FindComponentByIdVisitor(id) { @Override public VisitorResult visit(final WComponent comp) { VisitorResult result = super.visit(comp); if (result == VisitorResult.CONTINUE) { // Save closest UIC as processing tree setResult(new ComponentWithContext(comp, UIContextHolder.getCurrent())); } return result; } }; doTraverse(root, visibleOnly, visitor); return visitor.getResult() == null ? null : visitor.getResult().getContext(); }
/** * {@inheritDoc} */ @Override public List<WebElement> findElements(final SearchContext searchContext) { List<WebElement> result = new ArrayList<>(); ComponentWithContext[] components = null; UIContextHolder.pushContext(getContext()); try { components = TreeUtil.findWComponents(getComponent(), path, visibleOnly); } finally { UIContextHolder.popContext(); } if (components.length != 0) { componentClass = components[0].getComponent().getClass(); } for (ComponentWithContext comp : components) { WComponent cmp = comp.getComponent(); UIContext cmpUic = comp.getContext(); UIContextHolder.pushContext(cmpUic); try { List<WebElement> resultForComp = findElement(searchContext, cmpUic, cmp, getValue()); result.addAll(resultForComp); } finally { UIContextHolder.popContext(); } } return result; }
UIContext tuic = triggerWithContext.getContext(); UIContextHolder.pushContext(tuic); try {
UIContext uic = triggerWithContext.getContext(); UIContextHolder.pushContext(uic); try {
/** * Retrieves the application title for the given context. This mess is required due to WWindow essentially existing * as a separate UI root. If WWindow is eventually removed, then we can just retrieve the title from the root * WApplication. * * @param uic the context to check. * @return the current application title. */ private String getApplicationTitle(final UIContext uic) { WComponent root = uic.getUI(); String title = root instanceof WApplication ? ((WApplication) root).getTitle() : null; Map<String, String> params = uic.getEnvironment().getHiddenParameters(); String target = params.get(WWindow.WWINDOW_REQUEST_PARAM_KEY); if (target != null) { ComponentWithContext targetComp = WebUtilities.getComponentById(target, true); if (targetComp != null && targetComp.getComponent() instanceof WWindow) { try { UIContextHolder.pushContext(targetComp.getContext()); title = ((WWindow) targetComp.getComponent()).getTitle(); } finally { UIContextHolder.popContext(); } } } return title == null ? "" : title; }
/** * {@inheritDoc} */ @Override public void serviceRequest(final Request request) { // Check if this is a targeted request targetId = request.getParameter(Environment.TARGET_ID); if (targetId == null) { throw new SystemException("No target id request parameter"); } ComponentWithContext target = WebUtilities.getComponentById(targetId, true); if (target == null) { throw new SystemException("No target component found for id " + targetId); } // go straight to the target component. attachUI(target.getComponent()); UIContextHolder.pushContext(target.getContext()); try { super.serviceRequest(request); } finally { UIContextHolder.popContext(); } }
UIContextHolder.pushContext(target.getContext()); try { xml.appendTagOpen("ui:ajaxtarget");
/** * Temporarily replaces the environment while the UI is being rendered. * * @param renderContext the context to render to. */ @Override public void paint(final RenderContext renderContext) { if (windowId == null) { super.paint(renderContext); } else { // Get the window component ComponentWithContext target = WebUtilities.getComponentById(windowId, true); if (target == null) { throw new SystemException("No window component for id " + windowId); } UIContext uic = UIContextHolder.getCurrentPrimaryUIContext(); Environment originalEnvironment = uic.getEnvironment(); uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target)); UIContextHolder.pushContext(target.getContext()); try { super.paint(renderContext); } finally { uic.setEnvironment(originalEnvironment); UIContextHolder.popContext(); } } }
/** * Temporarily replaces the environment while the UI prepares to render. * * @param request the request being responded to. */ @Override public void preparePaint(final Request request) { if (windowId == null) { super.preparePaint(request); } else { // Get the window component ComponentWithContext target = WebUtilities.getComponentById(windowId, true); if (target == null) { throw new SystemException("No window component for id " + windowId); } UIContext uic = UIContextHolder.getCurrentPrimaryUIContext(); Environment originalEnvironment = uic.getEnvironment(); uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target)); UIContextHolder.pushContext(target.getContext()); try { super.preparePaint(request); } finally { uic.setEnvironment(originalEnvironment); UIContextHolder.popContext(); } } }
getComponent()); Assert.assertSame("Incorrect context returned for find WApplication", uic, result. getContext()); Assert.assertSame("Incorrect context returned for find WTextArea", uic, result.getContext()); result.getComponent()); Assert.assertSame("Incorrect context returned for find WContainer/WTextArea", uic, result. getContext()); UIContext row2Context = repeaterChild.getRowContext("2"); Assert.assertSame("Incorrect context returned for find WText[1]", row2Context, result. getContext()); row2Context = repeaterChild.getRowContext("2"); Assert.assertSame("Incorrect context returned for find WApplication/WText[1]", row2Context, result.getContext());
.getComponent()); Assert.assertSame("Incorrect context for root", uic1, WebUtilities.getComponentById(root. getId()).getContext()); Assert.assertSame("Incorrect component for static child", staticChild, WebUtilities.getComponentById(staticChildId).getComponent()); Assert.assertSame("Incorrect context for static child", uic1, WebUtilities.getComponentById( root.getId()) .getContext()); .getComponent()); Assert.assertSame("Incorrect context for root", uic2, WebUtilities.getComponentById(root. getId()).getContext()); Assert.assertNull("Incorrect component for removed child", WebUtilities.getComponentById( staticChildId));