Problem with JTreeMap and Wicket

14 views
Skip to first unread message

Fei

unread,
Apr 1, 2008, 8:45:42 PM4/1/08
to informative-workspace-discuss
After a brief overview of the JTreeMap library, I think we have a
quite difficult problem of using it with Wicket. The JTreeMap provides
a Swing component to render the treemap, but in Wicket there is no
simple way to render a Swing component since Wicket is almost like
replacement for the Swing. And after all, Swing is mostly used for
desktop application. Here are some possible solutions I am thinking:

1. Make the JTreeMap as something like a client side application, so
that we would have separated countdown/checklist and the map that one
is a webapp, and another is a desktop application. I don't know how
well is this going to work together since there is hardly connection
between these 2 parts.

2. Use a totally different framework like wingS (http://
wingsframework.org), which is designed for developing Swing webapp.
Consider the time we put into learning the Wicket framework, I am
afraid learning another framework in just a month can be a good idea.

3. Make the JTreeMap as an applet. Again, the problem is how to use
applet in Wicket. Since the JTreeMap can load in a XML file to create
the treemap, maybe we can just create a non-Wicket page that contains
the applet. This seems to be most feasible solution so far for me.

Any better idea?

Nathan Britton

unread,
Apr 2, 2008, 5:11:37 AM4/2/08
to informative-wo...@googlegroups.com
I think the Applet would be our best chance, but we're running into problems with that too.  I'm really anxious about moving to client-side, because my assumption this whole time would be net-based to connect teams... but this JTreeMap is really cool and I think we should do it whatever the cost.  Lets ask Johnson tomorrow and see what he thinks about client-side.
--
Nathan Britton

The only impossible task is to find an impossible task.

Jianfei Liao

unread,
Apr 2, 2008, 5:52:58 AM4/2/08
to informative-wo...@googlegroups.com
Yeah, I am feeling that we need a major change of what we would be implementing if we are going to this JTreeMap. Getting the Applet to work with Wicket is harder than I expected, and there are couple potential problems I can already think of right now. After all, this JTreeMap is a Swing component, and even the guy in the Wicket mailing list told me that Swing and Wicket are not meant to be used together. (I asked a question of how to use swing component/applet in wicket, and the general responses are there is no simple way to get around it.)

Nathan Britton

unread,
Apr 2, 2008, 5:57:03 AM4/2/08
to informative-wo...@googlegroups.com
Yeah, so even if we don't go client-side, we're probably going to have to dump most of the code we've done so far.  Honestly, I think if we just focus on this for the rest of the project and forget submitting the report and all that junk, we might be able to pull it off in time.  I want to have something useful by the end of this and nothing has seemed so promising as this Heat Map.

Philip Johnson

unread,
Apr 2, 2008, 12:44:29 PM4/2/08
to informative-workspace-discuss
A little googling on 'wicket applet' found me the following:

http://martijndashorst.com/blog/2006/02/02/swing-it-applet-takes-over-canvas/

It's an old post, but you might want to contact the author and see if
it's still relevant.

Cheers,
Philip

p.s. I am quite interested in whether you folks can pull off Wicket +
Applet integration, because I want to do the exact same thing for
another hackystat UI application!

On Apr 1, 11:57 pm, "Nathan Britton" <nathanb...@gmail.com> wrote:
> Yeah, so even if we don't go client-side, we're probably going to have to
> dump most of the code we've done so far. Honestly, I think if we just focus
> on this for the rest of the project and forget submitting the report and all
> that junk, we might be able to pull it off in time. I want to have
> something useful by the end of this and nothing has seemed so promising as
> this Heat Map.
>
>
>
> On Tue, Apr 1, 2008 at 11:52 PM, Jianfei Liao <jianfeil...@gmail.com> wrote:
> > Yeah, I am feeling that we need a major change of what we would be
> > implementing if we are going to this JTreeMap. Getting the Applet to work
> > with Wicket is harder than I expected, and there are couple potential
> > problems I can already think of right now. After all, this JTreeMap is a
> > Swing component, and even the guy in the Wicket mailing list told me that
> > Swing and Wicket are not meant to be used together. (I asked a question of
> > how to use swing component/applet in wicket, and the general responses are
> > there is no simple way to get around it.)
>
> > On 4/1/08, Nathan Britton <nathanb...@gmail.com> wrote:
>
> > > I think the Applet would be our best chance, but we're running into
> > > problems with that too. I'm really anxious about moving to client-side,
> > > because my assumption this whole time would be net-based to connect teams...
> > > but this JTreeMap is really cool and I think we should do it whatever the
> > > cost. Lets ask Johnson tomorrow and see what he thinks about client-side.
>

Philip Johnson

unread,
Apr 2, 2008, 9:04:44 PM4/2/08
to informative-workspace-discuss
I searched the Wicket user forum and found the following thread:

http://www.nabble.com/Applet-Question-tt12932157.html#a12932157

http://www.nabble.com/Applet-problem-tt15357386.html#a15357386

http://www.nabble.com/wicket-applet-issue-tt14173518.html#a14176577

It seems like basic use of an applet is trivially simple in Wicket.

Here's the official sun documentation on applets:

http://java.sun.com/applets/

I think if you read through this, you'll be able to integrate the
applet-based version of JTreeMap with Wicket.

Nathan Britton

unread,
Apr 2, 2008, 9:14:10 PM4/2/08
to informative-wo...@googlegroups.com
Cool.  I had a feeling that using the applet wouldn't be as big an overhaul as starting over would be.  Thanks!

Jianfei Liao

unread,
Apr 2, 2008, 9:56:15 PM4/2/08
to informative-wo...@googlegroups.com
I already read those thread from the Wicket user forum, and here's what I tried and the problems I encountered last night:
 
My war file is structured as follow:
 
META-INF/
  |_ MANIFEST.MF
web/
  |_ WEB-INF/
  |         |_ classes/
  |         |         |_ mypacakge/
  |         |                      |_ myapplet.class
  |         |_ lib/
  |         |     |_ jtreemap.jar
  |         |_ web.xml
  |_ appletpage.html
 
Then in the html file, I have the <applet> tag like this:
<applet code="mypackage.myapplet.class" codebase="WEB-INF/classes" archive="jtreemap.jar" />
 
The "codebase" attribute is required, otherwise it would give a ClassNotFoundException for not finding the myapplet class. But this would still result in another exception that some other dependent classes are not found, which are inside the jtreemap.jar file. The "archive" attribute is supposed to fix this, but then it will look into the SAME directory as specified in the codebase, "WEB-INF/classes" in this case. Therefore, it's not found. I even manually move the jar file inside the /classes folder, it still cannot find the necessary class. I tried unzip the jar file into folders, then it gave me some AccessControlDenial exception.
 
All the trial mentioned above is still under the war FOLDER, it's not packed into a war file yet (I simply clicked the html file to test it). If I war it and deploy it into tomcat, the URL http://localhost:8080/myproject/treemap (I mounted the URL in Wicket so looks like that instead of the default long odd url) would become part of the "codebase" attribute (according to a thread I read from http://www.nabble.com/How-to-display-applet-in-wicket--tt10426521.html#a10426521), which would give more trouble.
 
I wouldn't say this is impossible to do, but obviously it's not as simple as it sounds. The dependency of the jar files and the URL change when it gets deployed are the main problems for integrating the Wicket and applet. I would read more on the sun tutorial to see how can I solve this problem, but any ideas and helps would be appreciated.

 

Philip Johnson

unread,
Apr 3, 2008, 4:47:13 AM4/3/08
to informative-workspace-discuss
It might help if you take Wicket out of the equation.

Start by just creating a plain vanilla webapp (no wicket) that has a
single static html page with the embedded <applet>.

Make sure you can get the JTreeMap to display correctly in this case.
For example, follow the hint in the forum that says you shouldn't put
the jar file inside WEB-INF because that's not a publically accessable
folder.

Once you can get the applet to work fine in a plain webapp, you'll
probably find that it's easy to get working in Wicket.

You'll probably find that it helps to read the documentation about
applets and try some of the examples (if they have them).

Cheers,
Philip

Fei

unread,
Apr 5, 2008, 9:18:40 PM4/5/08
to informative-workspace-discuss
Ok, finally made some progress. I got the applet up in the simplest
webapp (no wicket). It turns out I have to create a separate folder to
store all the related applet classes and dependent jar files in it. So
the directory ends up like this now:

META-INF/
|_ MANIFEST.MF
WEB-INF/
|_ classes/
| |_ mypacakge/
| |_ otherstuff.class
| |_ myapplet.class
|_ lib/
| |_ otherfiles.jar
| |_ jtreemap.jar
|_ web.xml
applets/
|_ mypackage/
| |_ myapplet.class
|_ jtreemap.jar
appletpage.html

And the applet tag is as follow:

<applet code="mypackage.myapplet.class" codebase="applets/"
archive="jtreemap.jar" height="550" width="800" />

This would allow the applet to run inside the webapp. HOWEVER, there
is still 1 more problem: the applet is not allowed to read/write the
local files. Because the way we make the applet communicate with
outside is to read in a data file, we use the "user.home" system
property in the code. Applets are not allowed to read that property.
After some googling, there seems to be 2 ways to solve this problem:

1. Signed the applet to give it a digital certificate. This requires
jaring the applet, and using the "keytool" utility that comes with the
Java distribution. Also we have to automate the process in Ant build
file since it's required for every deployment. Here is one tutorial I
found that might help: http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html

2. Use the java.policy file to grant the permission. In the bin
folder, there's a file called java.policy.applet, which is generated
by eclipse. It grants all permission for the applet, which is why the
applet running inside eclipse is able to read/write local files. I
couldn't find too much info on how to use this file, though. After
all, it's sort of advanced and the signed applet is generally the more
preferable way to go.

Let's try to sign our applet.

Philip Johnson

unread,
Apr 6, 2008, 12:44:39 PM4/6/08
to informative-workspace-discuss
> HOWEVER, there
> is still 1 more problem: the applet is not allowed to read/write the
> local files.

The general approach here is to realize that the applet _can_ read/
write files on the machine it was loaded from (i.e. the web server).
It cannot read/write files on the machine the user is displaying the
applet on (i.e. the client, or browser-side machine).

So, the way you want to approach this is to have a web application
where the user requests actions in the browser which result in data be
generated on the web-server side, which can then be accessed by the
applet and displayed.

If you go this route, you don't need to sign the applet, etc., because
you don't have to ask the user to give you permission to read/write
files on the local machine. This will make your users much happier.

Cheers,
Philip
Reply all
Reply to author
Forward
0 new messages