How to refresh Java Applet? - applet

I'm trying to use Java Applet for my website.
but I have a problem with refresh java applet content.
here is my code, (AppletTest.java)
import java.applet.*;
import java.awt.*;
public class AppletTest extends Applet{
public void init(){
}
public void stop(){
}
public void paint(Graphics g){
g.drawString("ABC",20,20); //I will draw DEF and FFF after ABC.
}
}
and HTML is (appletTest.html)
<body>
<applet code="AppletTest.class" name='AppletTest' width='500' height='300' style='border:1px solid #cdcdcdl'>
<param name='cache_option' value='no'> // I put this code to avoid browser remember applet but it does not work. :(
</applet>
</body>
Firstly I draw 'ABC' and It draw well.
and I change 'ABC' to 'DEF' and compile again and run it.
it draw 'DEF' well. And I change 'DEF' to 'FFF' and compile and run.
but it does not change to 'FFF'. it still 'DEF'. I refresh the page many time but it is not changed.
I think my browser remember pre applet content. so to avoid it, I put the <param name='cache_option' value='no'> code into applet tag. but it does not work...
anybody know this, please advice me.
Thank you!

Applets should be tested in tools like applet viewer or Appleteer, which do not cache classes. If testing in a browser, ensure the Java Console is open (there is an option in the Java Control Panel) & type Ctrl-X (I think that is 'clear class cache') before refreshing the page.
I put the <param name='cache_option' value='no'> code into applet tag..
That only works with recent JREs. What JRE version has the user got installed?

You can also enable Java Console (Java Control Panel>Advanced>Java Console>Show console) and after every new compilation you can use 'x' option in this console to clear classloader cache. Then simply click refresh on the website and that's all.

Related

Apache Wicket does not load (or display) static image

I am currently working my way into wicket and developed a small demo application. Now I want to display a static image in that application (to be more specific, this image should be added to a panel which is then added to the home page).
This is what I have so far:
1) The HTML code for the panel that should hold the image. There is no specific wicket code present, it should only hold an image present in the project structure.
<html><body>
<wicket:panel>
Just some static text inside the image panel...<br/>
<img src="test.jpg"></img>
</wicket:panel>
</body></html>
The panel is called ImagePanel and all three files (ImagePanel.java, ImagePanel.html, test.jpg) are located in the same package.
2) The Java code for the ImagePanel - rather short, as there is nothing really to do:
public class ImagePanel extends Panel {
public ImagePanel(String id) {
super(id);
}
}
3) The HTML code for the homepage:
<html><body>
<div wicket:id="dynamicComponent"></div>
</body></html>
4) And the Java code for the homepage:
public HomePage() {
add(new ImagePanel("dynamicComponent"));
}
Please note the following: In practice, HomePage.java and ImagePanel.java are located in different OSGi-projects. The code for the HomePage is simplified here, in practice the ImagePanel is located via a service and dynamically added. This works so far, I see the static text. But the image is not loaded, I just get this broken-image-thumbnail.
Like I said, all three ImagePanel-related files (.java, .html, the picture) are located in the very same package. I can access the Panel itself from the homepage-project as I can see the static text. But I can't get the image to display.
The Application Server I use is Jetty, started from inside the project that holds the homepage.
Update:
I've narrowed the problem to the following:
Everything works fine as long as I only display static text inside of ImagePanel.html. As soon as I want to add the image (even if inside of a wicket:link-tag as suggested below) I end up with the following exception:
[qtp401543768-20] WARN org.apache.wicket.core.util.lang.WicketObjects - Could not resolve class [plugin.ImagePanel]
java.lang.ClassNotFoundException: plugin.ImagePanel
So without the image the server bundle is able to load the class from the gui bundle and display the static text. With the image I end up with a ClassNotFoundException for the same class.
Find the whole stack trace here: stack trace
In your template, put a around
<wicket:link>
<img src="test.jpg"></img>
</wicket:link>
Wicket will rewrite the url so that the image works.
If you have a dynamic Image that you want to load a Package Resource, you use PackageResourceReference.
e.g.
add(new Image("myImage", new PackageResourceReference(MyClass.class, "test.jpg"));
Thanks for the help, though meanwhile I managed to solve the problem myself. It was not a sole wicket problem but also some difficulties with the OSGi-bundle-setup.
As I mentioned before, the ImagePanel is located in a different OSGi bundle than the HomePage. The problem arised as all Wicket-libraries are located in the HomePage-bundle (I get Linker errors if both bundles use their own libraries). Therefore loading an image in the ImagePanel used classes located in the HomePage-bundle who now couldn't access the image.
I solved the problem by introducing an OSGi-Service in the ImagePanel-bundle that passes all used images as byte arrays to the HomePage-bundle. The HomePage-bundle has now access to all resources and registers them as SharedResource with an id given again by the ImagePanel-bundle.
After registration, it is no problem to access the images in the ImagePanel-bundle via SharedResourceReference.

GWT: avoid setting window.name on web application load

I wanted to use window.name as a holder for some identifier to use whenever page refresh happens (or being forced). However, I've noticed that GWT sets it to rename-to property value defined in module definition. Is there any way to avoid it?
P.S. I know I can use sessionStorage, or maybe even some other mechanism. I'm just curious about this specific case -- would like to know how could I override such GWT behavior.
Are you sure the window is getting its name changed? I recall that the module changes the iframe that it loads into, but not the global window. Or are you using a different linker? Or referring to the window as window in your jsni instead of $wnd?
private native void setWindowName(String newName) /*-{
$wnd.name=newName;
}-*/;

GWT showing blank page.

my GWT app is designed to be multipage. And separated into modules. So far all other modules works, except for my 'login' module.
I don't understand why when I access http://127.0.0.1:8888/login.html?gwt.codesvr=127.0.0.1:9997 I get a blank page.
LoginEntryPoint:
public void onModuleLoad() {
GWT.log("Loading module");
if (!Window.Location.getPath().toLowerCase().endsWith("login.html")) {
return;
}
RootPanel.get().add(new Button("Test"));
}
And in the login.html file:
<script type="text/javascript" language="javascript" src="login/login.nocache.js"></script>
and finally in the Login.gwt.xml:
<entry-point class='com.mygwtapp.client.LoginEntryPoint' />
How to fix this kind of situation?
Make sure also when you compile the project Remember to add the new module to be compiled
Right Click on the Project >> Google >> Gwt Compile >> Add (add your new module)
Does your log statement happen? If not, is the login.cache.js file even loading (use firebug or the like to check)? If so, can you set a breakpoint on that log statement and step forward, see where it gets to?
And is there anything shown when you run in web mode?
If the login.nocache.js isn't loading, make sure you added rename-to="login" in the module tag, make sure it is actually being compiled, etc
This problem was happening to me, and I figured out that it was all because I had Buttons in a FormPanel. As soon as I removed them from the FormPanel everything showed up again. I am not sure where exactly you were sticking the button up there, but you might want to try removing the button out of the equation, trying another type of panel and some text, and see if it shows up without the button present.
If you are running in hosted mode, this if if (!Window.Location.getPath().toLowerCase().endsWith("login.html")) { is true, so no button should appear. Try changing the "endsWith" by "contains" method

How can i read a HTML file and display the content in GWT with its css and Javascripts

I just want to read a HTML file and display its content in a GWT widget. Already I have done it but i'm not getting its css and javascripts. So can anyone help me to get the content with its css and javascripts?
I tried the following code,
public class FrameExample implements EntryPoint {
public void onModuleLoad() {
Frame frame = new Frame("http://www.google.com/");
RootPanel.get().add(frame);
}
}
I got a rectangular box only. But I don't get the expected result. Can you help me?
Forget everything I said, you can get the answerer here!
(Iframe not displaying some pages)
Basically: google has a mechanism to detect if it is not hosted in a iframe. This of course raises the question why they us it in their examples.....
BTW: a site like http://en.wikipedia.com works.

How to prevent GWT onload flicker in the Web Application Starter Project?

I'm new to GWT, and I'm sure this is answered in SO somewhere but I've yet to find
I downloaded the GWT 2.0 eclipse plugin, and was pleased to see it comes with a starter project.
However, I was surprised that when running it, there is an unpleasent flickering...
The text loads without the CSS first
It takes a while untill the select box apears
(If you don't see the flicker, try and press F5 to refresh)
All mature GWT apps seem to have a loader before that but I didn't find an easy, standard way to add it.
It seems this app loads in this order: (correct me please if I mixed it up, its only my guess)
Basic layout HTML,
All JavaScript, and CSS
Runs the logic on the "onload" event (soonest time your compiled javaScript can start - ?)
So I can't programmatically add a loading spinner before GWT was loaded, a bit of a catch 22 for me
Am I missing something basic? is there a best practice way to add that initial spinner?
I was thinking simply adding a div with an animated gif, and in the onload event - hide it.
But I'm sure there is something better.
Let me know if this is a duplicate question
Update: found this related question, not answering mine though...
I've handled this problem before by not using the GWT module to load CSS, but loading it directly in the tag itself. If you do this, the browser will always load the CSS first, even before the GWT JS is loaded.
This means you'll lose a bit of flexibility and speed, but its the only workaround I've used so far.
EDIT: Extra info cause I want the bounty :D
If you do not remove the
<inherits name='com.google.gwt.user.theme.standard.Standard'/> from your module.gwt.xml file, then the GWT standard theme is loaded in the JS file that GWT creates. This JS file loads after the HTML page renders, and injects the CSS after load. Hence the flicker.
To avoid the flicker, you can comment out that line and insert your own stylesheet into the <head> of your HTML file. This ensures your CSS loads before the HTML renders, avoiding any flicker. If you really want the GWT theme, you get it out of the source code.
To use a spinner with GWT is quite easy. One simple way would be to keep it in a div with an id in the HTML file itself. Then, in the onModuleLoad(), simply hide that div by calling RootPanel.get("spinner").setVisible(false);
That should show the spinner till GWT loads itself.
Here's what we do to implement a spinner.
You put something like the following HTML just below the script line that loads your application (ie. the one with nocache.js). e.g.:
<div id="loading">
<div id="loading-msg">
<img src="icons/loading-page.gif" lt="loading">
<span>Loading the application, please wait...</span>
</div>
</div>
Then in your application EntryPoint you reach into the page using the DOM and remove that div. e.g.
final RootPanel loading = RootPanel.get("loading");
if (loading != null) {
DOM.removeChild(RootPanel.getBodyElement(),
loading.getElement());
}
Ehrann: I'm afraid the practice mentioned in the above answers is the only way for now. GWT doesn't provide similar features to show/hide a "loading" frame "on the fly". I guess one of the reason is that this requirement is not so "common" for all GWT users, one person might want a very different style of the "loading" than others. So you have to do that by yourself.
You can have a look at the GXT showcase page (based on GWT too): http://www.extjs.com/explorer/ for how they do that. For the source of it, download Ext GWT 2.1.0 SDK here: http://www.extjs.com/products/gxt/download.php and check the samples/explorer folder after extracting it. For details see the edit below:
EDIT
Check the source code for http://www.extjs.com/examples/explorer.html and you can see a div with id "loading". For each samples (extending Viewport), GXT.hideLoadingPanel(loadingPanelId) is called in onAttach() (the initialization), which hides the loading frame.
Check source code of Viewport here
Check source code of GXT.hideLoadingPanel here
You can do it in a similar way.
You could put an HTML loading message in the host page (use style attributes or embed the style tag in the header to make sure that it's styled), and remove the message once your modules has loaded, e. g. Document.get().getBody() with .setInnerHTML("") or .removeChild(), and then present your application programmatically however you want.