Search in sources :

Example 6 with StaticBindingValueProvider

use of com.vaadin.flow.template.angular.StaticBindingValueProvider in project flow by vaadin.

the class TemplateElementStateProviderTest method testElementAttributes.

@Test
public void testElementAttributes() {
    ElementTemplateBuilder builder = new ElementTemplateBuilder("div").setAttribute("a1", new StaticBindingValueProvider("v1")).setAttribute("a2", new StaticBindingValueProvider("v2"));
    Element element = createElement(builder);
    Assert.assertEquals("v1", element.getAttribute("a1"));
    Assert.assertEquals("v2", element.getAttribute("a2"));
    Assert.assertEquals(new HashSet<>(Arrays.asList("a1", "a2")), element.getAttributeNames().collect(Collectors.toSet()));
}
Also used : ElementTemplateBuilder(com.vaadin.flow.template.angular.ElementTemplateBuilder) Element(com.vaadin.flow.dom.Element) StaticBindingValueProvider(com.vaadin.flow.template.angular.StaticBindingValueProvider) Test(org.junit.Test)

Example 7 with StaticBindingValueProvider

use of com.vaadin.flow.template.angular.StaticBindingValueProvider in project flow by vaadin.

the class DefaultElementBuilderFactory method setBinding.

private void setBinding(Attribute attribute, ElementTemplateBuilder builder, Element element) {
    String name = attribute.getKey();
    if (name.startsWith("(")) {
        if (!name.endsWith(")")) {
            throw new TemplateParseException("Event listener registration should be in the form (click)='...' but template contains '" + attribute + "'.");
        }
        String key = extractKey(name, 1);
        builder.addEventHandler(key, attribute.getValue());
    } else if (name.startsWith("[")) {
        if (!name.endsWith("]")) {
            throw new TemplateParseException("Property binding should be in the form [property]='value' but template contains '" + attribute + "'.");
        }
        handlePropertyParsing(attribute, builder, element, name);
    } else {
        /*
             * Regular attribute names in the template, i.e. name not starting
             * with [ or (, are used as static attributes on the target element.
             */
        builder.setAttribute(name, new StaticBindingValueProvider(attribute.getValue()));
    }
}
Also used : TemplateParseException(com.vaadin.flow.template.angular.TemplateParseException) StaticBindingValueProvider(com.vaadin.flow.template.angular.StaticBindingValueProvider)

Aggregations

StaticBindingValueProvider (com.vaadin.flow.template.angular.StaticBindingValueProvider)7 Test (org.junit.Test)5 Element (com.vaadin.flow.dom.Element)4 ElementTemplateBuilder (com.vaadin.flow.template.angular.ElementTemplateBuilder)4 TextTemplateBuilder (com.vaadin.flow.template.angular.TextTemplateBuilder)4 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)1 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)1 TemplateParseException (com.vaadin.flow.template.angular.TemplateParseException)1 TextTemplateNode (com.vaadin.flow.template.angular.TextTemplateNode)1 HashMap (java.util.HashMap)1