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

  • Home
  • SEARCH
  • 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 6724631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:42:46+00:00 2026-05-26T09:42:46+00:00

We have coded a browser plugin. It fires custom events like ‘mycustomevent’. I need

  • 0

We have coded a browser plugin. It fires custom events like ‘mycustomevent’. I need to incorporate (i.e. assign listeners for) these custom events into GWT. Here is my plugin class in GWT.

class PluginObject extends Composite implements HasMyCustomEventHandler{
    private Element plugin;
    private HTML html;
    private HandlerManager handlerManager;

    public PluginObject(){
        handlerManager = new HandlerManager(this);
        html = new HTML("<object id='plugin0' type='application/x-ourplugin' width='300' height='300'>"
                       +"<param name='onload' value='pluginLoaded' />"
                       +"</object>");
        initWidget(html);
        plugin = html.getElement().getFirstChildElement();
    }
}

Here is how I am adding it in my View (I am using gwtp). It is being added and is functioning correctly in the page and I can call its js functions from gwt with JSNI.

@Inject
public MyPageView(){

    ...
    plugin = new PluginObject();
    panel.add(plugin);
}

I need to be able to assign handlers for the events fired from the plugin. I’d like to be able to do the following in my presenter but thus far I have been un able to get it wired up.

@Override
protected void onBind(){
    super.onBind();
    registerHandler(getView().getPluginObject().addMyCustomEventHandler(
        new MyCustomEventHandler() {
            @Override
            public void onMyCustomEvent(MyCustomEvent event) {
                // call some other presenter stuff here...
            }
        }));
}

The above mentions a few additional classes. I have a MyCustomEvent class defined, a MyCustomEventHandler interface that extends EventHandler defined, and a HasMyCustomEventHandler interface that extends HasHandlers defined but after wiring them all up I get nothing. I’ve omitted them for brevity, I’d be glad to add anything that might help.

I can add event listeners in bare js.

obj.addEventListener("mycustomevent", function(){ foo(); }, false);

and catch the event (foo() gets called) every time so I’m confident the events are being fired.

I’ve tried adding the following to my PluginObject class, but this is just me guessing from things I’ve found searching. It has not worked.

public HandlerRegistration addMyCustomEventHandler(MyCustomEventhandler handler){
    return handlerManager.addHandler(MyCustomEvent.TYPE, handler);
}

What is the proper approach here?

  • 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-05-26T09:42:47+00:00Added an answer on May 26, 2026 at 9:42 am

    Here is what I ended up doing in the PluginObject. I’d love to hear ways to improve it. I got hung up a while on subscribeToBrowserEvents() and the reference to ‘this’. Initially I was calling the addEvent method and referring to

    this.@....
    

    Which was referencing the wrong place at runtime. More about the issue here in this bit of the JSNI docs. Enjoy.

    class PluginObject extends Composite implements HasMyCustomEventHandler{
    
    public PluginObject(){
        handlerManager = new HandlerManager(this);
    
        html = new HTML("<object id='plugin0' type='application/x-myplugin' width='300' height='300'>"
                             +"<param name='onload' value='pluginLoaded' />"
                             +"</object>");
        initWidget(html);
        plugin = html.getElement().getFirstChildElement();      
    }
    
    public void bindBrowserEvents(){
        subscribeToBrowserEvents(plugin);
    }
    
    public void eventHandlerMethod(String message){
        MyCustomEvent event = new MyCustomEvent(message);       
        fireEvent(event);
    }
    @Override
    public void fireEvent(GwtEvent<?> event){
        handlerManager.fireEvent(event);
    }
    
    public native void subscribeToBrowserEvents(Element eventObject) /*-{
    
        var pluginReference = this;
    
        // bind the listener
        function addEvent(obj, name, func)
        {
            if (window.addEventListener) {
                obj.addEventListener(name, func, false); 
            } else {
                obj.attachEvent("on"+name, func);
            }
        }
    
        addEvent(eventObject.br,'mycustomevent', 
            function(message){
                pluginReference.@com.Name.SomeTest2.client.core.PluginObject::eventHandlerMethod(Ljava/lang/String;)(message);
            });
    }-*/;
    
    @Override
    protected void onAttach(){
        super.onAttach();
        // bind in the onAttach, it was not working earlier. I assume the plugin needs to exist before the bindings will work  
        bindBrowserEvents();
    }
    
    @Override
    public HandlerRegistration addMyCustomEventHandler(MyCustomEventHandler handler)
    { 
        return handlerManager.addHandler(MyCustomEvent.TYPE, handler);
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, every other browser works fine with the method I have coded so far
What code do you need to add in PHP to automatically have the browser
I have been using the JEditable plugin for JQuery and I would like to
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
I have a java script code that works fine when run through a browser,
I have coded some JavaScript to perform an ajax call in an asp.net application.
I have coded my own tiny static DAL class for .NET Compact Framework and
I have coded the next function. But surely someone has a more elegant way
I have coded up an ASP.NET website and running on win'08 (remotely hosted). The
I have coded a view that relies on a scalar function value for one

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.