Java – vaadin flow: the difference between components and elements

In vaadin flow, there are elements besides components

In the Javadoc of the element, say:

What does this actually mean? What do you do at a higher level and when you use elements and components?

Solution

As a practical example, let's consider the HTML tag < input > You can create a server-side element instance to provide < input > as element myelement = new element ("input") in the browser

In addition, suppose you want to configure the placeholder text of the element, for example < input placeholder = "enter your name here" > Use the element API, which is myelement SetAttribute ("placeholder", "enter your name here")

As a final example, you also added a listener that forwards value change events to the server You also need to configure which parts of the browser event to send to the server and access the value in the listener: myelement addEventListener(“change”,event – > System.out.println(“New value:”event) . getEventData( “element.value”)). addEventData( “element.value”);.

You can build the entire application this way, but it's not convenient You want to have a class that knows the name of the input tag instead of entering a string every time Instead of using the generic setAttribute, you need the setplaceholder method and remember the name of the attribute Finally, you need a way to add a value change listener, where the new value can be used as event getValue().

This is where the component enters the picture It allows you to create an input class that extends component and provides Java APIs for these functions Under the hood, the input component will use the element API, but the user who hides it as the input class does not need to know the implementation details

In addition, components can be based on other components instead of using element directly This is usually how you create the components that make up the component Views in your application

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>