Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:10:25+00:00 2026-06-08T21:10:25+00:00

I need to make a custom GWT widget from HTML and javascript code. The

  • 0

I need to make a custom GWT widget from HTML and javascript code. The javascript code should be called on the widget, but the javascript should receive the widget DOM component as a parameter.

Also, the widget’s HTML has to be directly dependent on the arguments, given to the widget’s constructor.

What is the “idiomatic” way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:10:26+00:00Added an answer on June 8, 2026 at 9:10 pm

    It is quite simple. You can start by extending Widget class.

    To create DOM representation, you need to use Document.get() (or other old api depends on what you prefer).
    To call external javascript you will need to use JSNI.

    Also you will have to override onDetach and onAttach methods, so you can notify external JS when your element is added to dom, and when external JS should perform some cleanup (if needed).

    Example code:

    public class MyWidget extends Widget{
    
         public MyWidget(String params) {
             Document document = Document.get();
             DivElement divElement = document.createDiv();
             divElement.setInnerHtml(params);
             setElement(divElement); //important, widget needs to know it's root element
         }
    
    
         private static native void doJsMagic(Element element)/*-{ //notifies js about element
             $wnd.doSomething(element);
         }-*/;
    
         private static native void undoJsMagic(Element element)/*-{ 
            //notifies js that it should do some cleanup (if needed)
            //since it is unaware of GWT widget lifecycle
            $wnd.undoSomething(element)
    
         }-*/;
    
         @Override
         public void onAttach() {
            super.onAttach();
            doJsMagic(getElement());
         }
    
         @Override
         public void onDetach() {
            super.onDetach();
            undoJsMagic(getElement());
         }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have string that i need to make custom parser but i am stuck
I need to make a custom dialog with 4 options but as far as
I need to make a custom permission framework that not only allows/forbids users but
I need to make custom text field which will format numeric values according to
What would i need to put in the SortIP function to make the custom
I need to make a custom download manager as I am using android 2.2
Somehow I need to make a custom file-open form. I manage to retrieve the
I am customizing wordpress blog and I have a need to make custom sidebar
I need to make a custom list-style markers. Now it's done by adding element
so right now I need to make a custom control for a c# project,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.