DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • How To Develop a Modern Image Gallery With HTML, CSS, and JavaScript
  • React, Angular, and Vue.js: What’s the Technical Difference?
  • An Overview of Programming Languages
  • Ultimate Guide to FaceIO

Trending

  • Unleashing the Power of Microservices With Spring Cloud
  • API Design
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  • Exploring the Evolution and Impact of Computer Networks
  1. DZone
  2. Coding
  3. Languages
  4. Integrating HTML and JavaScript in Vaadin 7: Part Two

Integrating HTML and JavaScript in Vaadin 7: Part Two

Nicolas Fränkel user avatar by
Nicolas Fränkel
CORE ·
Aug. 13, 12 · Tutorial
Like (0)
Save
Tweet
Share
29.99K Views

Join the DZone community and get the full member experience.

Join For Free

In the previous article, we successfully integrated a custom-made tooltip over our hyperlinks. In this article, we'll integrate an already existing tooltip library.

Since we already played with Twitter Bootstrap library, we'll try to reuse their code.

If you follow this site regularly, we already used the Bootstrap library, or more exactly the GWT porting of the library in the Using GWT widgets serie. This time, we'll use the library directly, without any third-party GWT wrapper.

The process mirrors what we already did when creating custom HTML code.

  • The first step is to create the server part, which is the extension. For JavaScript components, note that there exists a specialized class, JavaScriptExtension. Moreover, we have to tell Vaadin which scripts will be used: those scripts can either be local to the webapp or available through an absolute URL. It's done through a simple annotation.
    @JavaScript({ "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js", "bootstrap.js", "bootstrap_connector.js" })
    public class JavascriptTooltipExtension extends AbstractJavaScriptExtension {
    
        public void extend(Link link) {
    
            Resource resource = link.getResource();
    
            String display = resource instanceof ExternalResource ? ((ExternalResource) resource).getURL().toString() : "???";
    
            getState().setDisplay(display);
    
            super.extend(link);
    
            attachTooltip();
        }
    
        protected void attachTooltip(Object... commandAndArguments) {
    
            invokeCallback("attach", commandAndArguments);
        }
    
        @Override
        protected Class<? extends ClientConnector> getSupportedParentType() {
    
            return Link.class;
        }
    
        @Override
        public BootstrapTooltipState getState() {
    
            return (BootstrapTooltipState) super.getState();
        }
    }
  • Next, we have to provide the aforementioned local scripts. This is done by packaging them in the WAR as the previous class. So, if the extension was in the com.morevaadin.vaadin7.html.js package, put the scripts in exactly the same one
  • Last but not least, we have to provide the JavaScript glue that bind the components together. You probably noticed the invokeCallback() in the server code: it's the connector between server and client code. Vaadin will search for an anonymous JavaScript function under the package name (where dots have been replaced by underscores) that provide a subfunction named as the first argument of the invokeCallback() argument. This is the reason why we parameterized the bootstrap_connector.js script previously (though you're free to call it what you want).
    window.com_morevaadin_vaadin7_html_js_JavascriptTooltipExtension = function() {
    
        this.attach = function(options) {
    
            var connectorId = this.getParentId();
    
            var element = this.getElement(connectorId);
    
            var a = element.childNodes[0]; 
    
            a.rel = "tooltip";
            a.title = this.getState().display;
    
            $(a).tooltip();
        }
    }
    The code itself depends on the particular library.

There are two important things to note:

  • Nothing prevents you for providing multiple features in your server-side API since you can invoke whichever callback you want on the client side.
  • In our case, we have access to the jQuery API since it was configured in the extension.

Compared to wrapping our own HTML, wrapping already existing JavaScript is a breeze. In conclusion, Vaadin 7 makes it possible to easily integrate JavaScript without the need for GWT wrappers. If (a part of) your team is fluent in JavaScript, it's a real asset for your applications.

The code of this article can be found on GitHub.

HTML JavaScript Vaadin

Opinions expressed by DZone contributors are their own.

Related

  • How To Develop a Modern Image Gallery With HTML, CSS, and JavaScript
  • React, Angular, and Vue.js: What’s the Technical Difference?
  • An Overview of Programming Languages
  • Ultimate Guide to FaceIO

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: