Button Click Event Causing Object Error

I’ve run into a problem that I have no idea what the solution could be.

I have two “pages” in the application, WeeklyWidget and Monthly widget. Both extend ContentWidget.

I initialize them as

weekly_widget = new WeeklyWidget();
monthly_widget = new MonthlyWidget();
content_panel.setWidget(home_widget);

and then using History tokens, I change the content_panel

public void onHistoryChanged(String historyToken) {
		if (historyToken.equals("monthlyReports")) {
			content_wrapper.setWidget(monthly_widget);
		} else if (historyToken.equals("weeklyReports")) {
			content_wrapper.setWidget(weekly_widget);
		} else if (historyToken.equals("home")) {
			content_wrapper.setWidget(home_widget);
		}

	}

Everything APPEARS ok, and the content panel does change to reflect the appropriate widget. However, depending on which widget is initialized first (first code sample above initializes weekly before monthly), then a button in that widget does not work. In this case, a button on weekly widget does not work. The error is

17:32:18.390:TMR0:DEBUG:EventHandler:mousing over [Button ID:isc_OID_14]
17:32:18.953:MDN8:INFO:EventHandler:Target Canvas for event 'mousedown': [Button ID:isc_OID_14]
17:32:18.953:MDN8:DEBUG:EventHandler:Bubbling event 'prepareForDragging', target '[Button ID:isc_OID_14]' has handler: Canvas.prepareForDragging()
17:32:18.953:MDN8:DEBUG:EventHandler:Event 'prepareForDragging' bubbled to top
17:32:18.953:MDN8:DEBUG:EventHandler:No dragTarget, not dragging
17:32:18.953:MDN8:DEBUG:EventHandler:Event 'mouseDown' bubbled to top
17:32:18.953:MDN8:DEBUG:EventHandler:Event 'mouseStillDown' bubbled to top
17:32:19.031:MUP3:INFO:EventHandler:Target Canvas for event 'mouseup': [Button ID:isc_OID_14]
17:32:19.046:MUP3:WARN:Log:Error:
	'Object required'
	in http://localhost:8888/com.gnets.GnetsProject/GnetsProject.html
	at line 1610
    Element.getOffsetLeft(_1=>[DIVElement]{ID:isc_O})
    Element.$yw(_1=>"left", _2=>[DIVElement]{ID:isc_O}, _3=>[BODYElement]{nodeName:BODY}, _4=>false)
    Element.$s4(_1=>[DIVElement]{ID:isc_O}, _2=>[BODYElement]{nodeName:BODY}, _3=>false)
        "return this.$yw(isc.Canvas.LEFT,_1,_2,_3)"
    Canvas.$s4(_1=>undef)
    Canvas.getPageLeft()
    Canvas.containsPoint(_1=>490, _2=>181, _3=>false)
    Canvas.visibleAtPoint(_1=>490, _2=>181, _3=>undef, _4=>undef)
    EventHandler.$k5(_1=>Obj{type:error}, _2=>undef)
    EventHandler.handleMouseUp(_1=>Obj{type:error}, _2=>undef)
    EventHandler.dispatch(_1=>EventHandler.handleMouseUp(), _2=>Obj{type:error})
    anonymous(event=>undef)
        "var returnVal=arguments.callee.$ch.isc.EH.dispatch(arguments.callee.$j2,event);return returnVal;"

It seems as if the second (weekly widget or monthly widget) to be initialized is overwriting something somehow. If I reverse the initialization order, then the working / non-working buttons switch.

Does anyone know what the problem might be or how I can detect it? Code in next posting.

public class MonthlyWidget extends ContentWidget{
	
	//VerticalPanel panel_2;
	Button create_monthly_button;
	HTML body;
	
	public MonthlyWidget() {
		
		title = "Monthly Reports";
		description = "Modify/Create monthly reports here";
		create_monthly_button = new Button("Create Monthly Report");
		create_monthly_button.setWidth(160);

		body = new HTML("<p>This is the body.  We hope this updates.</p>");

		panel = new VerticalPanel();

		create_monthly_button.addClickHandler(new ClickHandler() {
					public void onClick(ClickEvent event) {
						new MonthlyReportEdit();
						
					}
				});

		panel.add(create_monthly_button);
		panel.add(body);

		initWidget(panel);
	}
public WeeklyWidget() {
		title = "Weekly Reports";
		description = "Modify weekly reports here";
		//search_panel = new SearchWidget();
		create_weekly_button = new Button("Create Weekly Report");
		create_weekly_button.setWidth(160);

		body = new HTML("<p>This is the body.  We hope this updates.</p>");

		panel = new VerticalPanel();

		//panel.add(search_panel);

		create_weekly_button.addClickHandler(new ClickHandler() {
					public void onClick(ClickEvent event) {
						
						new WeeklyReportEdit();
						
					}
				});

		panel.add(create_weekly_button);
		
		panel.add(body);

		initWidget(panel);

	}

ContentWidget:

public abstract class ContentWidget extends Composite {
	VerticalPanel panel;
	protected String description;
	protected String title;

	public String getDescription() {
		return description;
	}

	public String getTitle() {
		return title;
	}

Do you have the browser in strict mode (<DOCTYPE> tag)? Try removing that.

No. It’s transitional.

If I change my History section to

public void onHistoryChanged(String historyToken) {
		if (historyToken.equals("monthlyReports")) {
			content_wrapper.setWidget(new MonthlyWidget());
		} else if (historyToken.equals("weeklyReports")) {
			content_wrapper.setWidget(new WeeklyWidget());
		} else if (historyToken.equals("home")) {
			content_wrapper.setWidget(new HomeWidget());
		}

	}

And simply set the content_wrapper (panel) to a new instance of the various Widget (page views?), then both buttons work.

It seems like it relates to the ClickListener (maybe?) The developers console never shows ‘click’ bubble to the top. Mouse up is the last thing that registers before the error. Using the old method (initialize widgets, switch to already created instances rather than new ones in History) When the first instance is created, everything works fine. When the next widget has it’s instance created, it seems as if the ClickListener is lost on the first widget - that is, the object cannot be found anymore, or is considered undefined.

In the developers console, two lines appear in the bottom section, evaluate JS expression.

isc_OID_14
isc_OID_167

When I click Eval JS, I get the following:

19:20:53.656:WARN:Log:Error:
‘‘isc_OID_167’ is undefined’
in http://localhost:8888/com.gnets.GnetsProject/GnetsProject.html
at line 276
anonymous(_1=>“‘isc_OID_167’ is undefined”, _2=>“http://localhost:8888/com.gnets.GnetsPro…”[62], _3=>276)

I’m not sure why isc_OID_167 is undefined, and I’m also not quite sure what it is supposed to reference.

I’ve also noticed that the following line only occurs if I initialize two instances of ContentWidget (whether it be weekly and then monthly, or home and then weekly, or anything) and assign those instances to variables.

17:32:19.046:MUP3:WARN:Log:Error:
‘Object required’
in http://localhost:8888/com.gnets.GnetsProject/GnetsProject.html
at line 1610

Strangely, if I always use new WeeklyWidget() or new MonthlyWidget() and never create variables referencing the various instances, the error never appears, even if the History changes and a different widget is called (using new). I at least thought that if I always used new, then I initially would not get the error, but when I did create another instance by changing the browser history, then I would see the error. But I did not.

Worse news: I’ve noticed that also when I have more than two instances (again, see very first code chunk in first post, which has two), the AccordionPanel which I use for navigation ALSO does not work. You can click on the headers and they will not expand or shrink. If I cut it down to only one instance being stored in a variable, then they work again. So somehow by creating those instances and storing them in variables, it seems to kill all my event handling except for the one button which was created in the last instance. The accordionPanel throws the same errors in developers console as the nonworking buttons do.

You sound like you have a bunch of colliding global IDs. Are you seeing any messages related to this in your Developer Console?

About the <DOCTYPE> tag, don’t worry about transitional vs not, just try removing it entirely.

I haven’t noticed anything regarding colliding global IDs. I’m not too familiar with the developers console, but if those errors should appear with the default settings then no. This is the full report for default logging settings from starting of the program to clicking a button that does not work.

21:00:46.765:INFO:Log:initialized
21:00:47.000:INFO:Log:isc.Page is loaded
21:00:55.125:TMR2:WARN:Log:Error:
	'Object required'
	in http://localhost:8888/com.gnets.GnetsProject/GnetsProject.html
	at line 1610
    Element.getOffsetLeft(_1=>[BODYElement]{nodeName:BODY})
    Element.$yw(_1=>"left", _2=>[DIVElement]{ID:isc_N}, _3=>[BODYElement]{nodeName:BODY}, _4=>false)
    Element.$s4(_1=>[DIVElement]{ID:isc_N}, _2=>[BODYElement]{nodeName:BODY}, _3=>false)
        "return this.$yw(isc.Canvas.LEFT,_1,_2,_3)"
    Canvas.$s4(_1=>undef)
    Canvas.getPageLeft()
    Canvas.$414(null, undef)
    Page.handleEvent(_1=>null, _2=>"resize", _3=>undef)
    EventHandler.$hr(_1=>true)
    EventHandler.$mn()
        "isc.EH.$hr(true)"
    Class.fireCallback(_1=>EventHandler.$mn(), _2=>undef, _3=>Array[0], _4=>Obj{length:2}, _5=>true) on [Class Timer]
    Timer.$in(_1=>"$ir0")
    anonymous()
        "isc.Timer.$in('$ir0')"

21:00:57.265:TMR3:WARN:Log:Error:
	'Object required'
	in http://localhost:8888/com.gnets.GnetsProject/GnetsProject.html
	at line 1610
    Element.getOffsetLeft(_1=>[BODYElement]{nodeName:BODY})
    Element.$yw(_1=>"left", _2=>[DIVElement]{ID:isc_O}, _3=>[BODYElement]{nodeName:BODY}, _4=>false)
    Element.$s4(_1=>[DIVElement]{ID:isc_O}, _2=>[BODYElement]{nodeName:BODY}, _3=>false)
        "return this.$yw(isc.Canvas.LEFT,_1,_2,_3)"
    Canvas.$s4(_1=>undef)
    Canvas.getPageLeft()
    Canvas.$414(null, undef)
    Page.handleEvent(_1=>null, _2=>"resize", _3=>undef)
    EventHandler.$hr(_1=>undef)
    callback(undefined=>undef)
        "isc.EH.$hr()"
    Class.fireCallback(_1=>"isc.EH.$hr()", _2=>undef, _3=>Array[0], _4=>Obj{length:2}, _5=>true) on [Class Timer]
    Timer.$in(_1=>"$ir35")
    anonymous()
        "isc.Timer.$in('$ir35')"

21:01:17.078:MUP1:WARN:Log:Error:
	'Object required'
	in http://localhost:8888/com.gnets.GnetsProject/GnetsProject.html
	at line 1610
    Element.getOffsetLeft(_1=>[BODYElement]{nodeName:BODY})
    Element.$yw(_1=>"left", _2=>[DIVElement]{ID:isc_O}, _3=>[BODYElement]{nodeName:BODY}, _4=>false)
    Element.$s4(_1=>[DIVElement]{ID:isc_O}, _2=>[BODYElement]{nodeName:BODY}, _3=>false)
        "return this.$yw(isc.Canvas.LEFT,_1,_2,_3)"
    Canvas.$s4(_1=>undef)
    Canvas.getPageLeft()
    Canvas.containsPoint(_1=>462, _2=>176, _3=>false)
    Canvas.visibleAtPoint(_1=>462, _2=>176, _3=>undef, _4=>undef)
    EventHandler.$k5(_1=>Obj{type:error}, _2=>undef)
    EventHandler.handleMouseUp(_1=>Obj{type:error}, _2=>undef)
    EventHandler.dispatch(_1=>EventHandler.handleMouseUp(), _2=>Obj{type:error})
    anonymous(event=>undef)
        "var returnVal=arguments.callee.$ch.isc.EH.dispatch(arguments.callee.$j2,event);return returnVal;"

The only other logging settings I tried was setting EventHandler to debug, which is in the first post.

Removing DOCTYPE entirely does not appear to change anything.

What would cause global IDs to collide, and what are considered global IDs? What could be done to prevent them? I only know of global variables and such from standard Java, but I haven’t defined anything as global.

There should be clearer errors for this, but, I think your HTML page either lacks a <body> or has some malformed / mismatched tags such that there is no <body> tag.

Or, you might be calling APIs on the History module before the <body> tag has been started. It would be invalid both to call the History module or to create any components from within the <head> of your document.

Neither of these seem to apply.

Here is my HTML file. It is essentially the default HTML file.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- The HTML 4.01 Transitional DOCTYPE declaration-->
<!-- above set at the top of the file will set     -->
<!-- the browser's rendering engine into           -->
<!-- "Quirks Mode". Replacing this declaration     -->
<!-- with a "Standards Mode" doctype is supported, -->
<!-- but may lead to some differences in layout.   -->

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!--                                           -->
    <!-- Any title is fine                         -->
    <!--                                           -->
    <title>GnetsProject</title>
    
    <!--                                           -->
    <!-- This script loads your compiled module.   -->
    <!-- If you add any GWT meta tags, they must   -->
    <!-- be added before this line.                -->
    <!--                                           -->
    <script type="text/javascript" language="javascript" src="com.gnets.GnetsProject.nocache.js"></script>
  </head>

  <!--                                           -->
  <!-- The body can have arbitrary html, or      -->
  <!-- you can leave the body empty if you want  -->
  <!-- to create a completely dynamic UI.        -->
  <!--                                           -->
  <body>
  
  	<div id="loading"><img src="images/loading_app.gif" /></div>

    <!-- OPTIONAL: include this if you want history support -->
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>

  </body>
</html>

And my Entry Point class,

public class GnetsProject implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		
		// Load StudentRecords
		StudentRecords.getInstance();
		
		MainPanel panel = new MainPanel();
		RootPanel.get().add(panel);
		
		// remove the loading message
		Element loading = DOM.getElementById("loading");
		DOM.removeChild(RootPanel.getBodyElement(), loading);

		if (!GWT.isScript()) {
			KeyIdentifier debugKey = new KeyIdentifier();
			debugKey.setCtrlKey(true);
			debugKey.setKeyName("D");

			Page.registerKey(debugKey, new KeyCallback() {
				public void execute(String keyName) {
					SC.showConsole();
				}
			});
		}

	}

The only time I access the DOM (at least purposefully) is here. StudentRecords.getInstance() loads records from the server. I add MainPanel to the body element, and remove the loading div tag.

MainPanel is a composite widget, which part of the code is provided in the original post. It consists of a NavigationWidget (accordion panel where the items are Hyperlinks), header image, and ContentWidget, which are laid out using a Dock layout in MainPanel. MainPanel implements HistoryListener, which changes the content_wrapper (using setWidget() ) in the Dock Layout to various ContentWidgets such as WeeklyWidget and MonthlyWidget(which are all composites) depending on which navigation link (from NavigationWidget accordionPanel items) is clicked. This is the main structure / architecture of the program.

Everything should happen in the BODY tag, as that is the only thing that I access directly - I just add the panel that encloses everything else to the body element in the Entry Point class.

Out of ideas. We’ll have to wait and see if anyone else ever reports a similar error.

BTW, it looks like you are freely intermixing GWT and SmartGWT widgets. Elsewhere we have pointed out that this is not a good idea and is something you should really only do when legacy reasons force you to - consider getting rid of this if you can, because what you’ve hit is likely to be an obscure interop bug.

Alright, well thanks for looking into it some.

When it comes to mixing GWT and SmartGWT widgets, would some GWT items be fine, such as Composite? Otherwise, how would one build composite widgets?

I can easily make the switch from a Dock Layout to using SmartGWT layout options, and generally most of the code is SmartGWT. However, I’m not sure how I would go about creating composites if SmartGWT doesn’t have the functionality. This seems like something that should be ok to use from GWT.

Same goes for things such as History and other standard vanilla classes.

In the meantime, I suppose I can just create new instances of the Widgets each time a link is created, as I do not believe anything really needs to be saved as the user navigates through (unless it is a form which specifically has a save button). The only reason I wouldn’t want to do this would be memory issues and other small things like that which may arise - do you know if there is any cleanup done during the lifetime of an application built with SmartGWT or GWT? Otherwise it seems like there will be a bunch of widgets floating around with nothing pointing to them. I know it is built with Javascript, but I’m not sure if Javascript has that sort of functionality.

Have You managed to find a solution for this problem? I’m getting similar errors in few places of my app and I have no idea where are they comming from. I’ll post it in a new thread if I won’t manage to solve it by myself quickly.

(note: I’m using SmartGWT 1.2 + Composite widgets)

I’ve found a solution! Took me shorter than I thought it would.

Try replacing all the GWT components with SmartGWT components. I had those issues since I was extending Composite class and was using some GWT components along as well (Button, DockPanel, etc.). When I changed my base class to VLayout and all other components as well, everything started to work.

One remark:
I was getting “Object required” error in few places of my app. Mainly when displaying the ListGrid (populated through DataSource), showing a DynamicForm (while debugging, I’ve found out it was being thrown while creating FormItem instances, even though I’ve supplied the necessary properties) and finally - while using DateItem (the component itself was properly rendered, but nothing happened when I’ve clicked on the combos or datepicker).

Anyways - try using only SmartGWT components and You should be fine.

Cheers!