Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Setting custom objects as tags (Read 2793 times)
alternative84
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 7
Joined: Jun 7th, 2010
Setting custom objects as tags
Jul 16th, 2010 at 7:19pm
Print Post  
Hi, I'm trying to assign a custom object that I defined to a node, and then retrieve it.

Here is the code of the custom object:

Quote:
function Datos(codigo, fechaCreacion, nombre, puestoResponsable, descripcion) {
this.codigo = codigo;
this.fechaCreacion = fechaCreacion;
this.nombre = nombre;
this.puestoResponsable = puestoResponsable;
this.descripcion = descripcion;
}

function DatosProceso(codigo, fechaCreacion, nombre, puestoResponsable, descripcion, estadoDeDisen) {
this.base = new Datos(codigo, fechaCreacion, nombre, puestoResponsable, descripcion);
this.estadoDeDisen = estadoDeDisen;
}


I create a new object and assign it to a node using "setTag()":

Quote:
var applet = <%= DiagramView.AppletElement %>;

nuevoProceso = new DatosProceso("", DateEditProceso.GetDate(), txtNombreProceso.GetText(), "", txtDescripcionProceso.GetText(), "");
applet.getDiagram().getActiveItem().setTag(nuevoProceso);


And then I try to retrieve it using "getTag()" and calling "alert" to show the "nombre" property:

Quote:
var applet = <%= DiagramView.AppletElement %>;
tag = applet.getDiagram().getActiveItem().getTag();
alert(tag.base.nombre);


but the browser doesn't show nothing.

When I check the type of "tag" using "typeof(tag)" it says that is a string, so I don't know if I have to do a casting or something else.

Thanks,
Juan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Setting custom objects as tags
Reply #1 - Jul 19th, 2010 at 8:22am
Print Post  
That works for me while the same page remains loaded in the browser. If you need the tag value to be preserved after posting the page back, you will have to add SerializeTagScript and DeserializeTagScript functions that convert from your JS type to string and back.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
alternative84
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 7
Joined: Jun 7th, 2010
Re: Setting custom objects as tags
Reply #2 - Jul 19th, 2010 at 7:47pm
Print Post  
Yes, that must be the problem, because when I call "setTag(...)" the page posts back automatically.

Anyway, I'd like to implement the SerializeTag and DeserializeTag events, but when I try to get the XML Element under which the tag data should be written, the Java console throws an exception.

Here's the code (very simple):
Code
Select All
function onSerializeTag(sender, args) {
    args.setHandled();
    alert(args.getTagElement().tagName);
} 



Here's the exception:
Code
Select All
JavaScript error while calling "onSerializeTag"
netscape.javascript.JSException: JavaScript error while calling "onSerializeTag"

at sun.plugin2.main.client.MessagePassingJSObject.newJSException(Unknown Source)

at sun.plugin2.main.client.MessagePassingJSObject.waitForReply(Unknown Source)

at sun.plugin2.main.client.MessagePassingJSObject.call(Unknown Source)

at com.mindfusion.diagramming.AppletEx.a(Unknown Source)

at com.mindfusion.diagramming.DiagramApplet.serializeTag(Unknown Source)

at com.mindfusion.diagramming.Diagram.a(Unknown Source)

at com.mindfusion.diagramming.XmlPersistContext.writeTag(Unknown Source)

at com.mindfusion.diagramming.DiagramItem.saveToXml(Unknown Source)

at com.mindfusion.diagramming.DiagramNode.saveToXml(Unknown Source)

at com.mindfusion.diagramming.ShapeNode.saveToXml(Unknown Source)

at com.mindfusion.diagramming.XmlPersistContext.a(Unknown Source)

at com.mindfusion.diagramming.Diagram.saveToXml(Unknown Source)

at com.mindfusion.diagramming.DiagramView.saveToXml(Unknown Source)

at com.mindfusion.diagramming.DiagramView.saveToXml(Unknown Source)

at com.mindfusion.diagramming.DiagramView.saveToString(Unknown Source)

at com.mindfusion.diagramming.DiagramApplet.saveToString(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 



Thanks,

Juan J. Gomez
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Setting custom objects as tags
Reply #3 - Jul 20th, 2010 at 7:33am
Print Post  
Hi,

These functions should convert from string to object and back, e.g. this serializes a hashtable of string values:

Code
Select All
function onDeserializeTag(tagString)
{
	var strings = tagString.split(";");
	var customProps = new Object();

	for (i = 0; i < strings.length; i += 2)
	{
		customProps[strings[i]] = strings[i + 1];
		alert(strings[i]);alert(strings[i+1]);
	}

	return customProps;
}

function onSerializeTag(tag)
{
	var s = "";
	for (var property in tag)
	{
		if (s.length != 0) s+= ";";
		if (tag.hasOwnProperty(property))
			s = s + property + ";" + tag[property];
	}
	return s;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint