new problems persisting state from applet into JavaScript page

99 views
Skip to first unread message

Stephen Bannasch

unread,
May 9, 2013, 1:15:55 PM5/9/13
to netlog...@googlegroups.com
State saving doesn't work here in this example anymore:

http://stepheneb.github.io/netlogo-gcc/index.html

Here's the code that's being executed:

https://github.com/stepheneb/netlogo-gcc/blob/master/lib/netlogo.js#L102-L114

I'm using instances of these Java classes:

java.io.StringWriter();
java.io.PrintWriter();
java.io.StringReader();

To create and restore NetLogo application state,

to make a text representation of state ... and an instance of java.io.StringWriter() to make a text representation of state.

I used to use this statement:

sw = new applet.Packages.java.io.StringWriter()

But the way I get them ... by introspecting into applet.Packages is now undefined.

sw = new applet.Packages.java.io.StringWriter();
pw = new applet.Packages.java.io.PrintWriter(sw);
sr = new applet.Packages.java.io.StringReader(nl_obj_state);

I suspect that perhaps recent changes the security model for Java applets have made applet.Packages undefined.

Anybody have any ideas how I can get this functionality back?

Seth Tisue

unread,
May 9, 2013, 1:50:13 PM5/9/13
to netlog...@googlegroups.com
>>>>> "Stephen" == Stephen Bannasch <stephen....@deanbrook.org> writes:

Stephen> I suspect that perhaps recent changes the security model for
Stephen> Java applets have made applet.Packages undefined.

Stephen> Anybody have any ideas how I can get this functionality back?

The most promising-looking page I turned up is this one:

https://bugzilla.mozilla.org/show_bug.cgi?id=748343

There seems to be a lot of info in the comments. Looks hairy.

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/

Stephen Bannasch

unread,
May 9, 2013, 4:15:12 PM5/9/13
to Seth Tisue, netlog...@googlegroups.com
Seth,

Would it be practical to add accessor methods to NetLogo so I could call methods to serialize state into a string, and restore state from a string?

---

More on the current issue:

I found this Oracle documentation:

http://jdk6.java.net/plugin2/liveconnect/#PER_APPLET_PACKAGES

And example:

http://jdk6.java.net/nonav/plugin2/liveconnect/PackageAccess.html

But the example no longer works.

If you open that page and open your console you'll see an error like this:

TypeError: app.Packages is undefined

Trying to execute this line:

app.Packages.java.lang.System.out.println("Testing printing to System.out");

Packag...ss.html (line 6)

If anyone can find an similar example that works using current Java plugins let me know.

Seth Tisue

unread,
May 10, 2013, 2:35:02 PM5/10/13
to netlog...@googlegroups.com
>>>>> "Stephen" == Stephen Bannasch <stephen....@deanbrook.org> writes:

Stephen> Seth, Would it be practical to add accessor methods to NetLogo
Stephen> so I could call methods to serialize state into a string, and
Stephen> restore state from a string?

I'm not clear why that would help? If you're able to instantiate and
call methods on classes on NetLogo, aren't you equally able to do the
same with java.io.StringReader?

Seth Tisue

unread,
May 12, 2013, 7:20:10 PM5/12/13
to netlog...@googlegroups.com
>>>>> "Stephen" == Stephen Bannasch <stephen....@deanbrook.org> writes:

Stephen> Seth, Would it be practical to add accessor methods to NetLogo
Stephen> so I could call methods to serialize state into a string, and
Stephen> restore state from a string?

>> I'm not clear why that would help? If you're able to instantiate
>> and call methods on classes on NetLogo, aren't you equally able to
>> do the same with java.io.StringReader?

Stephen> It appears that JavaScript no longer has access to static Java
Stephen> classes.

Ugh. Wow, that sucks. Anyway, well, yes, I think it would be practical
and not terribly hard to hack the source to add whatever glue methods
you need and then rebuild NetLogoLite.jar. On the 5.0.x branch, `./sbt
package` rebuilds the jars (including running ProGuard). If you need a
jar that supports Java 5, some extra steps are needed; see
https://github.com/NetLogo/NetLogo/wiki/Releasing#building

Stephen Bannasch

unread,
May 10, 2013, 3:41:32 PM5/10/13
to Seth Tisue, netlog...@googlegroups.com
At 2:35 PM -0400 5/10/13, Seth Tisue wrote:
> >>>>> "Stephen" == Stephen Bannasch <stephen....@deanbrook.org> writes:
>
> Stephen> Seth, Would it be practical to add accessor methods to NetLogo
> Stephen> so I could call methods to serialize state into a string, and
> Stephen> restore state from a string?
>
>I'm not clear why that would help? If you're able to instantiate and
>call methods on classes on NetLogo, aren't you equally able to do the
>same with java.io.StringReader?

It appears that JavaScript no longer has access to static Java classes.

I get access to these classes by introspecting into applet.Packages ... but applet.packages is now undefined.

I can still access classes and methods in the Java classes included in NetLogo.

So if I made these functions available as callable methods in NetLogo itself I'd be able to use this feature again from JavaScript.
Reply all
Reply to author
Forward
0 new messages