/** * {@inheritDoc} */ @Override public String toString() { return "ByWComponent:" + component.getId() + (value == null ? "" : (" with value \"" + value + '"')); }
/** * {@inheritDoc} */ @Override public String getId() { if (getIdName() == null && field != null && field.getIdName() != null) { return field.getId() + ID_FRAMEWORK_ASSIGNED_SEPERATOR + "fld"; } return super.getId(); }
/** * Returns the id of the related field ({@link #relatedField}). * * @return The id of the field that is related to this indicator. */ public String getRelatedFieldId() { return relatedField.getId(); }
/** * {@inheritDoc} */ @Override public String getId() { if (getIdName() == null && getForComponent() != null && getForComponent().getIdName() != null) { return getForComponent().getId() + ID_FRAMEWORK_ASSIGNED_SEPERATOR + "lbl"; } return super.getId(); }
@Override public String getId() { return component.getId(); } };
/** * @return the id of the component that this label is for. */ public String getLabelFor() { WComponent forComponent = getComponentModel().forComponent; if (forComponent == null) { return null; } return forComponent.getId(); }
/** * Retrieves the common name used by all collapsible components in the group. * * @return the common name to use. */ public String getGroupName() { if (collapsibleToggle != null) { return collapsibleToggle.getId(); } else if (!collapsibleList.isEmpty()) { // This is only to retain compatibility with the // previous implementation, and should be removed post-Sfp11, // as it doesn't make much sense to create a group without // something to toggle it. return collapsibleList.get(0).getId(); } return ""; }
/** * @param trigger the AJAX trigger to check * @return true if this is the current AJAX trigger */ public static boolean isCurrentAjaxTrigger(final WComponent trigger) { if (trigger == null) { return false; } AjaxOperation operation = AjaxHelper.getCurrentOperation(); return operation != null && operation.getTriggerId().equals(trigger.getId()); }
/** * {@inheritDoc} */ @Override public VisitorResult visit(final WComponent comp) { // Match if (findId.equals(comp.getId())) { handleFoundMatch(new ComponentWithContext(comp, UIContextHolder.getCurrent())); return VisitorResult.ABORT; } // Check name context. If different, then never match VisitorResult check = checkCorrectNameContext(comp, findId); if (check != null) { return check; } return VisitorResult.CONTINUE; }
/** * 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())); } }
/** * A convenience method to retrieve the ID of the component in the given context. * * @param component the component. * @param uic the context. * @return the ID of the component in the given context. */ private static String getComponentId(final WComponent component, final UIContext uic) { UIContextHolder.pushContext(uic); try { return component.getId(); } finally { UIContextHolder.popContext(); } } }
@Test public void testDuplicator() { // Launch the web browser to the LDE WebDriver driver = getDriver(); // Enter some text and use the duplicate button String inputFieldName = ((Container) getUi()).getChildAt(1).getId(); driver.findElement(By.name(inputFieldName)).sendKeys("dummy"); driver.findElement(By.xpath("//button[text()='Duplicate']")).click(); Assert.assertEquals("Incorrect text field text after duplicate", "dummydummy", driver.findElement(By.xpath("//input[@type='text']")).getAttribute("value")); // Clear the text driver.findElement(By.xpath("//button[text()='Clear']")).click(); Assert.assertEquals("Incorrect text field text after clear", "", driver.findElement(By.xpath("//input[@type='text']")).getAttribute("value")); } }
@Test public void testGetId() { WComponent backing = new WLabel(); setActiveContext(createUIContext()); InterceptorComponent interceptor = new InterceptorComponent(backing); Assert.assertEquals("Incorrect id returned", backing.getId(), interceptor.getId()); interceptor = new InterceptorComponent(interceptor); Assert.assertEquals("Incorrect id returned for nested interceptor", backing.getId(), interceptor.getId()); }
/** * Test that ByLabel works for CheckBoxes by label id. */ @Test public void testFindByLabelId() { // Launch the web browser to the LDE WebDriver driver = getDriver(); WContainer container = (WContainer) getUi(); WFieldLayout layout = (WFieldLayout) container.getChildAt(0); WField field = (WField) layout.getChildAt(0); String labelId = field.getLabel().getId(); String componentId = field.getField().getId(); WebElement checkBox = driver.findElement(new ByLabel(labelId)); Assert.assertNotNull("Unable to find checkbox by labelId", checkBox); Assert.assertEquals("Checkbox element ID does not match expected", componentId, checkBox.getAttribute("id")); }
/** * Test that ByLabel works for CheckBoxes by label text exact match. */ @Test public void testFindByLabelTextExact() { // Launch the web browser to the LDE WebDriver driver = getDriver(); WContainer container = (WContainer) getUi(); WFieldLayout layout = (WFieldLayout) container.getChildAt(0); WField field = (WField) layout.getChildAt(0); String labelText = field.getLabel().getText(); String componentId = field.getField().getId(); WebElement checkBox = driver.findElement(new ByLabel(labelText, false)); Assert.assertNotNull("Unable to find checkbox by label text", checkBox); Assert.assertEquals("Checkbox element ID does not match expected", componentId, checkBox.getAttribute("id")); }
@Test public void testFocussedIDAccessors() { UIContext uic = createUIContext(); WComponent component = new DefaultWComponent(); uic.setFocussed(component); uic.setUI(component); setActiveContext(uic); Assert.assertEquals("Incorrect focussed component id returned", component.getId(), uic. getFocussedId()); UIContext uic2 = createUIContext(); uic2.setUI(component); uic.setFocussed(component, uic2); Assert.assertEquals("Incorrect focussed component id returned with a different context", component.getId(), uic.getFocussedId()); }
/** * Paints the given WCollapsibleToggle. * * @param component the WCollapsibleToggle to paint. * @param renderContext the RenderContext to paint to. */ @Override public void doRender(final WComponent component, final WebXmlRenderContext renderContext) { WCollapsibleToggle toggle = (WCollapsibleToggle) component; XmlStringBuilder xml = renderContext.getWriter(); xml.appendTagOpen("ui:collapsibletoggle"); xml.appendAttribute("id", component.getId()); xml.appendOptionalAttribute("class", component.getHtmlClass()); xml.appendOptionalAttribute("track", component.isTracking(), "true"); xml.appendAttribute("groupName", toggle.getGroupName()); xml.appendEnd(); } }
/** * {@inheritDoc} */ @Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); if (getState() == ACTIVE_STATE) { // Can only remain active if it is AJAX targetted if (!isAjaxTargeted()) { getOrCreateComponentModel().state = INACTIVE_STATE; } } else if (getState() == MANUAL_OPEN_STATE) { getOrCreateComponentModel().state = ACTIVE_STATE; } if (getContent() != null) { AjaxHelper.registerContainer(getId(), getId(), getContent().getId()); } }
@Test public void testServiceRequestWithTarget() { // UI should change when a target is present in a request MockRequest request = new MockRequest(); request.setParameter(Environment.TARGET_ID, targetUI.getId()); interceptor.serviceRequest(request); Assert.assertNotSame("UI should change after serviceRequest with a target set", originalUI, interceptor.getUI()); Assert.assertSame("Incorrect new UI after serviceRequest with a target set", targetUI, interceptor.getUI()); }
@Test public void testGetComponentWithId() { Assert.assertSame("Incorrect component returned for root", root, TreeUtil. getComponentWithId(root, root.getId())); Assert.assertSame("Incorrect component returned for containerChild", containerChild, TreeUtil.getComponentWithId(root, containerChild.getId())); Assert.assertSame("Incorrect component returned for simpleChild", simpleChild, TreeUtil. getComponentWithId(root, simpleChild.getId())); Assert.assertSame("Incorrect component returned for repeaterChild", repeaterChild, TreeUtil. getComponentWithId(root, repeaterChild.getId())); Assert.assertSame("Incorrect component returned for grandChild", grandChild, TreeUtil. getComponentWithId(root, grandChild.getId())); UIContext row2Context = repeaterChild.getRowContext("2"); setActiveContext(row2Context); Assert.assertSame("Incorrect component returned for repeatedComponent row 2", repeatedComponent, TreeUtil.getComponentWithId(root, repeatedComponent.getId())); }