Java Code Examples for com.vaadin.client.WidgetUtil#setJsProperty()
The following examples show how to use
com.vaadin.client.WidgetUtil#setJsProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleElementBindingStrategy.java From flow with Apache License 2.0 | 6 votes |
private void updateProperty(MapProperty mapProperty, Element element) { String name = mapProperty.getName(); if (mapProperty.hasValue()) { Object treeValue = mapProperty.getValue(); Object domValue = WidgetUtil.getJsProperty(element, name); // We compare with the current property to avoid setting properties // which are updated on the client side, e.g. when synchronizing // properties to the server (won't work for readonly properties). if (WidgetUtil.isUndefined(domValue) || !Objects.equals(domValue, treeValue)) { Reactive.runWithComputation(null, () -> WidgetUtil.setJsProperty(element, name, PolymerUtils.createModelTree(treeValue))); } } else if (WidgetUtil.hasOwnJsProperty(element, name)) { WidgetUtil.deleteJsProperty(element, name); } else { // Can't delete inherited property, so instead just clear // the value WidgetUtil.setJsProperty(element, name, null); } }
Example 2
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 6 votes |
private void assertDeferredPolymerElement_originalReadyIsCalled( Element element) { initPolymer(element); mockWhenDefined(element); NativeFunction function = NativeFunction.create("this['foo']='bar';"); WidgetUtil.setJsProperty(element, "ready", function); Binder.bind(node, element); runWhenDefined(element); NativeFunction readyCall = new NativeFunction("this.ready();"); readyCall.call(element); assertEquals("bar", WidgetUtil.getJsProperty(element, "foo")); }
Example 3
Source File: GwtMultipleBindingTest.java From flow with Apache License 2.0 | 6 votes |
public void testBindModelPropertiesDoubleBind() { String name = "custom-div"; Element element = Browser.getDocument().createElement(name); WidgetUtil.setJsProperty(element, "localName", name); initPolymer(element); NativeFunction function = NativeFunction.create(""); WidgetUtil.setJsProperty(element, "set", function); Binder.bind(node, element); node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo") .setValue("bar"); Reactive.flush(); node.setBound(); Binder.bind(node, element); }
Example 4
Source File: ServerEventObject.java From flow with Apache License 2.0 | 5 votes |
/** * Gets or creates <code>element.$server</code> for the given element. * * @param element * the element to use * @return a reference to the <code>$server</code> object in the element */ public static ServerEventObject get(Element element) { ServerEventObject serverObject = getIfPresent(element); if (serverObject == null) { serverObject = (ServerEventObject) JavaScriptObject.createObject(); serverObject.initPromiseHandler(); WidgetUtil.setJsProperty(element, "$server", serverObject); } return serverObject; }
Example 5
Source File: GwtPolymerModelTest.java From flow with Apache License 2.0 | 5 votes |
private Element createHtmlElement() { String name = "custom-div"; Element element = Browser.getDocument().createElement(name); WidgetUtil.setJsProperty(element, "localName", name); setupSetMethod(element); setupMockSpliceMethod(element); WidgetUtil.setJsProperty(element, "removeAttribute", new NativeFunction("")); WidgetUtil.setJsProperty(element, "getAttribute", new NativeFunction("return false;")); WidgetUtil.setJsProperty(element, "setAttribute", new NativeFunction("")); return element; }
Example 6
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 5 votes |
public void testReadyCallback_deferredPolymerElement_readyIsCalledAndNotified() { element = Browser.getDocument().createElement("x-my"); WidgetUtil.setJsProperty(element, "localName", "x-my"); PolymerUtils.addReadyListener(element, () -> WidgetUtil.setJsProperty(element, "baz", "foobar")); assertDeferredPolymerElement_originalReadyIsCalled(element); assertEquals("foobar", WidgetUtil.getJsProperty(element, "baz")); }
Example 7
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 5 votes |
private Element createAndAppendElementToShadowRoot(Element shadowRoot, String id, String tagName) { Element childShadowRootElement = Browser.getDocument() .createElement(tagName); childShadowRootElement.setId(id); shadowRoot.appendChild(childShadowRootElement); if (id != null) { JsonObject obj = Json.createObject(); WidgetUtil.setJsProperty(obj, id.toString(), childShadowRootElement); WidgetUtil.setJsProperty(element, "$", obj); } return childShadowRootElement; }
Example 8
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 4 votes |
public void testBindVirtualChild_existingShadowRootChildren_searchById() { addShadowRootElement(element); String id = "@id"; StateNode childNode = createChildNode(id, element.getTagName()); StateNode virtualChild = createChildNode(id, element.getTagName()); StateNode shadowRoot = createAndAttachShadowRootNode(); shadowRoot.getList(NodeFeatures.ELEMENT_CHILDREN).add(0, childNode); Binder.bind(node, element); Reactive.flush(); JsonObject obj = Json.createObject(); WidgetUtil.setJsProperty(obj, id.toString(), childNode.getDomNode()); WidgetUtil.setJsProperty(element, "$", obj); addVirtualChild(node, virtualChild, NodeProperties.INJECT_BY_ID, Json.create(id)); Reactive.flush(); assertEquals( "Unexpected 'sendExistingElementWithIdAttachToServer' method call number", 4, tree.existingElementRpcArgs.size()); assertEquals( "Unexpected requested node id value argument in the 'sendExistingElementWithIdAttachToServer' method call", node, tree.existingElementRpcArgs.get(0)); assertEquals( "Unexpected requested node id value argument in the 'sendExistingElementWithIdAttachToServer' method call", virtualChild.getId(), tree.existingElementRpcArgs.get(1)); assertEquals( "Unexpected attached node id value argument in the 'sendExistingElementWithIdAttachToServer' method call", childNode.getId(), tree.existingElementRpcArgs.get(2)); assertEquals( "Unexpected identifier value argument in the 'sendExistingElementWithIdAttachToServer' method call", id, tree.existingElementRpcArgs.get(3)); }
Example 9
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 4 votes |
public void testBindVirtualChild_withDeferredElementInShadowRoot_byIndicesPath() { String childId = "childElement"; StateNode childNode = createChildNode(childId, element.getTagName()); NodeMap properties = childNode.getMap(NodeFeatures.ELEMENT_PROPERTIES); MapProperty fooProperty = properties.getProperty("foo"); fooProperty.setValue("bar"); WidgetUtil.setJsProperty(element, "ready", NativeFunction.create("")); Binder.bind(node, element); JsonArray path = Json.createArray(); path.set(0, 0); addVirtualChild(node, childNode, NodeProperties.TEMPLATE_IN_TEMPLATE, path); Element shadowRoot = Browser.getDocument().createElement("div"); List<Integer> expectedAfterBindingFeatures = Arrays.asList( NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS, NodeFeatures.ELEMENT_CHILDREN); Reactive.flush(); expectedAfterBindingFeatures.forEach(notExpectedFeature -> assertFalse( "Child node should not have any features from list " + expectedAfterBindingFeatures + " before binding, but got feature " + notExpectedFeature, childNode.hasFeature(notExpectedFeature))); WidgetUtil.setJsProperty(element, "root", shadowRoot); Element addressedElement = createAndAppendElementToShadowRoot( shadowRoot, childId, element.getTagName()); // add flush listener which register the property to revert its initial // value back if it has been changed during binding "from the client // side" and do update the property emulating client side update // The property value should be reverted back in the end Reactive.addFlushListener(() -> { tree.getRegistry().getInitialPropertiesHandler() .handlePropertyUpdate(fooProperty); fooProperty.setValue("baz"); }); PolymerUtils.fireReadyEvent(element); // the property value should be the same as initially assertEquals("bar", fooProperty.getValue()); expectedAfterBindingFeatures.forEach(expectedFeature -> assertTrue( "Child node should have all features from list " + expectedAfterBindingFeatures + " before binding, but missing feature " + expectedFeature, childNode.hasFeature(expectedFeature))); // nothing has changed: no new child assertEquals("No new child should be added to the element after attach", 0, element.getChildElementCount()); assertEquals( "No new child should be added to the shadow root after attach", 1, shadowRoot.getChildElementCount()); Element childElement = shadowRoot.getFirstElementChild(); assertSame( "Existing element should be the same as element in the StateNode object", addressedElement, childElement); }
Example 10
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 4 votes |
public void testReadyCallback_deferredPolymerElementAndNoListeners_readyIsCalled() { element = Browser.getDocument().createElement("x-my"); WidgetUtil.setJsProperty(element, "localName", "x-my"); assertDeferredPolymerElement_originalReadyIsCalled(element); }
Example 11
Source File: GwtPolymerModelTest.java From flow with Apache License 2.0 | 3 votes |
/** * Sets up mock splice method, that is called when model list is modified. * For each call, method stores call arguments in the element property named * argumentsArray. * * @param element * html element to set the method to */ private void setupMockSpliceMethod(Element element) { NativeFunction function = NativeFunction.create("path", "start", "deleteCount", "items", "this.argumentsArray ? this.argumentsArray.push(arguments) : this.argumentsArray = [arguments]"); WidgetUtil.setJsProperty(element, "splice", function); }
Example 12
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 3 votes |
private void assertPolymerElement_originalReadyIsCalled() { initPolymer(element); NativeFunction function = NativeFunction.create("this['foo']='bar';"); WidgetUtil.setJsProperty(element, "ready", function); Binder.bind(node, element); NativeFunction readyCall = new NativeFunction("this.ready();"); readyCall.call(element); assertEquals("bar", WidgetUtil.getJsProperty(element, "foo")); }