Embedded applet does not appear...

Hello:
I am trying to add an Embedded applet to an Application. I am trying this using the following code:

       
EmbeddedApp em=new EmbeddedApp();
em.setSource(
   new ClassResource(
      a.b.C.class,
      "Name of applet",
       this.getApplication()));
em.setType(Embedded.TYPE_OBJECT);
em.setArchive("dev.jar");
em.setWidth(250);
em.setHeight(250);
em.setEnabled(true);

GridLayout gl=new GridLayout(2,2);
gl.addComponent(em);

The GridLayout is then added to a TabSheet, which in turn is added to the Application Layout. Static Embedded images are displayed just fine. The class

a.b.C.class

is located on the classpath at runtime, otherwise I would get a “class not found” exception.

Can anyone help? Perhaps a simple example source code that shows how to load and display an appet using the Embedded object?

Thanks!!!

After banging my head against the wall a few hundred times, I think that this problem is related to the fact that the HTML code generated is Internet Explorer specfic (see link below)…I am using Firefox, which does not recognize the OBJECT tag. So what is needed is a mechanism to detect the client browser type (either via configuration file, or at runtime) and perhaps extending the class that generates the HTML.
Any suggestions from the user community?


http://java.sun.com/j2se/1.5.0/docs/guide/plugin/developer_guide/using_tags.html

Hi,

That does sound like the theme would render the applet wrong; we’ll look in to this, but if you’re in a hurry, here’s a possible solution:
Override the renderEmbedded function in your own theme, calling the standard renderer if it’s not your special case - in this case we’ll check the mimetype, so make sure to set it in your java code (
embedded.setMimeType(“application/x-java-vm”);
)
Then add this to your theme script (for the ‘example’ theme, the file to add to is
example/script/example-ajax-components.js
, as defined in
example/description.xml
)

renderEmbedded : function(renderer, uidl, target, layoutInfo) {
	
	if (uidl.getAttribute("mimetype") != "application/x-java-vm") {
		// render standard Embedded
		arguments.callee.$.renderEmbedded.call(this,renderer,uidl,target,layoutInfo);
		return;
	}

	var client = renderer.client;
    var theme = renderer.theme;
    
	// Create containing element
	var div = theme.createPaintableElement(renderer,uidl,target,layoutInfo);
	if (uidl.getAttribute("invisible")) return; // Don't render content if invisible

	// Render default header
	theme.renderDefaultComponentHeader(renderer,uidl,div,layoutInfo);
	var html = "<applet ";
	
	var val = uidl.getAttribute("src");
	var isThemeSource = (typeof val != 'undefined' && val != null && val.indexOf("theme://") == 0);
	if (isThemeSource)
		val = val.substring(8);
	if (val) html += "code=\""+val+"\" ";

	if (isThemeSource) {
		html += " codebase=\""+theme.root+"\" ";
	} else {
		val = uidl.getAttribute("codebase");
		if (val) html += " codebase=\""+val+"\" ";
	}
	
	val = uidl.getAttribute("width");
	if (val) html += " width=\""+val+"\" ";
	
	val = uidl.getAttribute("height");
	if (val) html += " height=\""+val+"\" ";
	
	
	val = uidl.getAttribute("standby");
	if (val) html += " standby=\""+val+"\" ";
	
	val = uidl.getAttribute("mimetype");
	if (val) html += " type=\""+val+"\" ";
	
	html += ">";		
	
	// Add all parameters
	var params = theme.getChildElements(uidl,"embeddedparams");
	if (params != null) {
		var len = params.length;
		for (var i=0;i<len;i++) {
			html += "<param name=\""+params[i]
.getAttribute("name")+"\" value=\""+params[i]
.getAttribute("name")+"\" />"
		}
	}
	html += "</applet>"
	div.innerHTML = html;

}

(This is a quickly done and not complete, you might have to modify slightly depending on your setup)

Hope this helps!

Best Regards,
Marc