Home » Eclipse Projects » Remote Application Platform (RAP) » when press F5 or update the page, an uncaught error occors
| |
Re: when press F5 or update the page, an uncaught error occors [message #1231835 is a reply to message #1231738] |
Wed, 15 January 2014 14:16 |
David Song Messages: 217 Registered: April 2011 |
Senior Member |
|
|
it is the second times to load the app, that is say, the loading of the new page, When I close the browser and reopen the browser again and load the app, everything is ok again.
even inside the app, I can switch the page by click the button, and the custom widget can be loaded well, but as long as I press F5 key or click the refresh button of the browser, the error occors.
[Updated on: Wed, 15 January 2014 14:40] Report message to a moderator
|
|
| |
Re: when press F5 or update the page, an uncaught error occors [message #1232250 is a reply to message #1231868] |
Thu, 16 January 2014 14:11 |
David Song Messages: 217 Registered: April 2011 |
Senior Member |
|
|
js code
jsmachine = {};
jsmachine.Machine = function(parent, renderer) {
this._renderer = renderer;
if(this._element == null){
this._element = this.createElement(parent);
}
this._svg = d3.select(this._element).append("svg").attr("class", "machine");
this._svg.append("rect").attr("width", "100%").attr("height", "100%").attr("fill", "#AAD8B0");
this._needsLayout = true;
this._paths = [];
this._texts = [];
var that = this;
rap.on("render", function() {
if (this._rendererJSONData) {
this._rendererMachine(this._rendererJSONData);
}
});
parent.addListener("Resize", function() {
that._resize(parent.getClientArea());
if (this._rendererJSONData) {
this._rendererMachine(this._rendererJSONData);
}
});
this._resize(parent.getClientArea());
};
jsmachine.Machine.prototype = {
createElement : function(parent) {
var element = document.createElement("div");
element.style.position = "absolute";
element.style.left = "0";
element.style.top = "0";
element.style.width = "100%";
element.style.height = "100%";
parent.append(element);
return element;
},
_rendererMachine : function(jsonData) {
if(this._paths.length == 0){
this._createMachine(jsonData);
this._createText(jsonData);
}else{
this._paths.data(jsonData).style("fill", function(d){
var c;
switch(d.status){
case 0:
c = "#0A7B83";
break;
case 1:
c = "#2AA876";
break;
case 2:
c = "#FFD265";
break;
case 3:
c = "#F19C65";
break;
case 4:
c = "#CE4D45";
break;
}
return c;
});
this._texts.data(jsonData).text(function(d) {return d.name;})
.style("cursor", "pointer")
.style("font-size", 10)
.attr("x", function(d) {return d.label_x;})
.attr("y", function(d) {return d.label_y;})
.append("tspan")
.attr("x", function(d) {return d.label_x;})
.attr("dy", 15).text(function(d) {return d.extendInfo;});
}
},
_createMachine : function(jsonData) {
var that = this;
var lineFunction = d3.svg.line().x(function(d) { return d.x;})
.y(function(d) {return d.y;})
.interpolate("linear");
this._paths = this._svg.selectAll("path").data(jsonData).enter().append("path");
this._paths.attr("d", function(d) { return lineFunction(d.anchorPoint); })
.attr("stroke", "#669966")
.attr("stroke-width", 1)
.attr("fill", function(d) {
var c;
switch(d.status){
case 0:
c = "#0A7B83";
break;
case 1:
c = "#2AA876";
break;
case 2:
c = "#FFD265";
break;
case 3:
c = "#F19C65";
break;
case 4:
c = "#CE4D45";
break;
}
return c;
})
.style("cursor", "pointer")
.on("dblclick", function(d) {that._mouseDoubleClick(d.mid);})
.on("click", function(d) {that._selectItem(d.mid);});
},
_createText : function(jsonData) {
this._texts = this._svg.selectAll("text").data(jsonData).enter().append("text");
this._texts.text(function(d) {return d.name;})
.style("font-size", 10)
.attr("x", function(d) {return d.label_x;})
.attr("y", function(d) {return d.label_y;})
.append("tspan")
.attr("x", function(d) {return d.label_x;})
.attr("dy", 15).text(function(d) {return d.extendInfo;});
},
_resize : function(clientArea) {
this._width = clientArea[2];
this._height = clientArea[3];
this._svg.attr("width", this._width).attr("height", this._height);
},
_selectItem : function(index) {
var remoteObject = rap.getRemoteObject(this);
remoteObject.notify("Selection", {"index" : index });
},
_mouseDoubleClick : function(index) {
var remoteObject = rap.getRemoteObject(this);
remoteObject.notify("MouseDoubleClick", {"index" : index });
},
destroy : function() {
var element = this._element;
if (element.parentNode) {
element.parentNode.removeChild(element);
}
},
setRendererJSONData : function(rendererJSONData) {
this._rendererJSONData = JSON.parse(rendererJSONData);
this._rendererMachine(this._rendererJSONData);
}
};
// TYPE HANDLER
rap.registerTypeHandler("jsmachine.Machine", {
factory : function(properties) {
var parent = rap.getObject(properties.parent);
return new jsmachine.Machine(parent);
},
destructor : "destroy",
properties : [ "rendererJSONData" ],
events : [ "Selection", "MouseDoubleClick" ]
});
java code:
package com.micromms.weave.machine;
import java.util.Map;
import org.eclipse.rap.json.JsonObject;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.lifecycle.WidgetUtil;
import org.eclipse.rap.rwt.remote.AbstractOperationHandler;
import org.eclipse.rap.rwt.remote.RemoteObject;
import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.SWTEventListener;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
public class JMachine extends Canvas {
private static final String REMOTE_TYPE = "jsmachine.Machine";
protected final RemoteObject remoteObject;
private String rendererJSONData;
public JMachine(Composite parent, int style) {
super(parent, style);
remoteObject = RWT.getUISession().getConnection().createRemoteObject(REMOTE_TYPE);
remoteObject.set("parent", WidgetUtil.getId(this));
remoteObject.setHandler(new AbstractOperationHandler() {
@Override
public void handleNotify(String eventName, JsonObject properties) {
if ("Selection".equals(eventName)) {
Event event = new Event();
event.index = properties.get("index").asInt();
notifyListeners(SWT.Selection, event);
}
if("MouseDoubleClick".equals(eventName)){
Event event = new Event();
event.index = properties.get("index").asInt();
notifyListeners(SWT.MouseDoubleClick, event);
}
}
public void handleSet(Map<String, Object> properties) {
if (properties.containsKey("rendererJSONData")) {
JMachine.this.rendererJSONData = (String) properties.get("rendererJSONData");
}
}
});
MachineResources.ensureJavaScriptResources();
}
@Override
public void addListener(int eventType, Listener listener) {
boolean wasListening = isListening(SWT.Selection);
super.addListener(eventType, listener);
if (eventType == SWT.Selection && !wasListening) {
remoteObject.listen("Selection", true);
}
boolean wasListeningDoubleClick = isListening(SWT.MouseDoubleClick);
//super.addListener(eventType, listener);
if(eventType == SWT.MouseDoubleClick && wasListeningDoubleClick){
remoteObject.listen("MouseDoubleClick", true);
}
}
@Override
public void removeListener(int eventType, Listener listener) {
boolean wasListening = isListening(SWT.Selection);
super.removeListener(eventType, listener);
if (eventType == SWT.Selection && wasListening) {
if (!isListening(SWT.Selection)) {
remoteObject.listen("Selection", false);
}
}
boolean wasListeningDoubleClick = isListening(SWT.MouseDoubleClick);
//super.removeListener(eventType, listener);
if (eventType == SWT.MouseDoubleClick && wasListeningDoubleClick) {
if (!isListening(SWT.MouseDoubleClick)) {
remoteObject.listen("MouseDoubleClick", false);
}
}
}
@Override
protected void removeListener(int eventType, SWTEventListener listener) {
super.removeListener(eventType, listener);
}
String getRemoteId() {
return remoteObject.getId();
}
public String getRendererJSONData() {
checkWidget();
return rendererJSONData;
}
public void setRendererJSONData(String rendererJSONData) {
checkWidget();
if(this.rendererJSONData != rendererJSONData){
this.rendererJSONData = rendererJSONData;
remoteObject.set("rendererJSONData", rendererJSONData);
}
}
}
|
|
|
Re: when press F5 or update the page, an uncaught error occors [message #1232605 is a reply to message #1232250] |
Fri, 17 January 2014 10:05 |
Tim Buschtoens Messages: 396 Registered: July 2009 |
Senior Member |
|
|
Hi.
I don't see any obvious problems that could lead to this error, so
possibly it's a server side issue. Maybe the id you send for the parent
it not valid?
However, this is one thing that can't work:
> rap.on("render", function() {
> if (this._rendererJSONData) {
> this._rendererMachine(this._rendererJSONData);
> }
> });
First, by making this an anonymous function (you hold to reference to
it) you can never unregister it (rap.off), and you should (in destroy).
Otherwise that function is called on "render" even after the widget is
disposed, which would definitely lead to errors.
Also, more importantly, the function has no "this", so there is no way
it could work. You must bind the function to your "this" before
registering it. Take a look how "bind", "bindAll", "rap.on" and
"rap.off" are used here:
http://git.eclipse.org/c/rap/incubator/org.eclipse.rap.incubator.richtext.git/tree/bundles/org.eclipse.rap.addons.ckeditor/src/resources/handler.js
Greetings,
Tim
--
Tim Buschtöns
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
|
Goto Forum:
Current Time: Fri Mar 29 05:26:26 GMT 2024
Powered by FUDForum. Page generated in 0.02678 seconds
|