Applet integration

Can we expect version 7 compatibility any time soon for this add-on?

Hello,

we’ve created and added an applet in our application using the Applet Integreation addon (v1.2.9) and Vaadin v 6.8.4.
Our application consists of a menu and a different page that is displayed according to the selected menuitem.

One of these pages contains an applet:


public class InfoPage extends VerticalLayout {
		
	public InfoPage() {
		super();
		
		this.addComponent(new Label("Information screen"));
		
		final AppletIntegration applet = new AppletIntegration() {
			
			@Override
			public void attach() {
				this.setAppletArchives(new String[] { "testapplet.jar", "appletintegration.jar" });
				this.setCodebase("applet/testcodebase/");
				this.setAppletClass("test/TestApplet");
				this.setWidth("300px");
				this.setHeight("300px");
			}
			
		};
		this.addComponent(applet);
		
                // ...
	}
}

The applet:


public class TestApplet extends AbstractVaadinApplet {
		
	@Override
	public void init() {
		super.init();
		System.out.println("Initializing TestApplet");
		//...
	}
	
	@Override
	protected void doExecute(final String command, final Object[] params) {
		System.out.println("Executing: " + command);
	}
	
}

Everthing works fine, when the page is loaded, the applet is added and initialized correctly (tested in FF, Google Chrome and IE).
When we select another menuitem, this page is destroyed (incl applet teardown) and another page is loaded.
In IE (tested in 6-7-8-9) for some reason the applet is ‘restarted’ as the message we print in init() is printed again in the java console. This doesn’t happen in Google Chrome and FF. This behaviour is a bit annoying for us as the init is executed unnecessarily during the ‘restart’. I’ve been looking around why this happens, but I can’t find a reason or solution for it. Does anybody knows why IE restarts the applet and how we can avoid this behaviour?

Thank you.

Sami –

I understand that integration of client-side java is not a priority for a server-side java framework, but this project really serves a need for some of us. Is there any chance to get this moved to Vaadin 7 soon? Is there somewhere I could vote for that?

– Sean

Vaadin 7 compatible any soon?

The author or the add-on is on a long summer vacation, so I would not expect any reply soon.
For this add-on, a full rewrite might be the best way to migrate it for Vaadin 7 as it could use many of the new features of Vaadin 7.

Hi Alexander!
I know it’s long ago, but currently I’m facing the same “Requested resource not found from filesystem or through class loader” -problem.

Would you be so kind and explain to me how you solved this issue, please?

Thanks!

hi

I am using this add-on but the one ported to vaadin 7 by
https://github.com/Haulmont/AppletIntegration

I did the exact thing you suggested but I am getting this error when trying to send variable to server :

Oct 30, 2013 10:23:33 PM com.vaadin.server.communication.ServerRpcHandler parseInvocation
WARNING: RPC call to v.v received for connector 9 but no such connector could be found. Resynchronizing client.

Do you have any idea, what could be the problem? I dont know what I am doing wrong.
Thanks in advance.

Hi Gokhan, I made it work receiving variables updates by adding super.attach() in the attach method. I was delaying Vaadin 7 because of this addon, now it seems I can move on…

appletCodigos = new AppletIntegration() {

            @Override
            public void attach() {
                // must be added
                super.attach();
                
                setAppletArchives(Arrays.asList(new String[] { "appletCodigos.jar,appletintegration-1.2.10.jar" }));
                setCodebase("VAADIN/");
                setAppletClass("ImprimirCodigos.class");
                setWidth("0px");
                setHeight("0px");

                /*
                 * Send parameters to the applet
                 */                
                setAppletParams("myParameters","values");                                                    
            }

            @Override
            public void changeVariables(Object source, Map variables) {
                super.changeVariables(source, variables);
                
                /*
                 * Recieve variables updates
                 */            
                
                if (variables.containsKey("estadoOk")) {                    
                    String strEstadoOk = (String) variables.get("estadoOk");            
                    if (strEstadoOk.equals("false")){;
                        System.out.println("Error");                    
                    } else {
                        appletCodigos.executeCommand("exit");    
                    }
                }    
            }
        };        
        view.addComponent(appletCodigos);
        appletCodigos.executeCommand("imprimirCodigos");

Hi everyone.
What is the straightforward way to clean an old jar’s cache?
If i remove the jar that i did use in setAppletArchives, the project still working.

PS: Thanks Maximiliano, I had the Gokhan’s problem too.
Thanks in advance.
Best Regards!

Edit1: I did a little research.
Using find command i found 2 jars.
The path to the cached jar is
" /home/francisco/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/BotQueueWeb/VAADIN/applet/"
i.e. this is on eclipse’s catalina_base temporary folder to deploy.
Why update “everything”, except this jar? To avoid unnecessary work?

Just figured out I don’t need any addon to integrate an applet. Check out this blogspot if you ran into trouble with the addon: http://acsadam0404.blog.com/2014/05/02/simple_vaadin7_applet_integration/

Hi everyone.
I’ve a little problem, my applet capture keyboard events correctly in windows OS, but not in linux.
I’m using chrome and firefox browsers on both OS.
I’ll test the “acsadam0404” solution if it fix it.
¿Some has the same problem?

Regards!

Hi I have a WebApp with Vaadin 7.0.7 and I want to Call an Applet for use a Token.

I did various tests:

  1. Use of AppletIntegration 1.2.9 but when I call applet there’s an Exception “ClassNotFoundException PaintTarget”
  2. Download Legacy 1.2.10 byhttps://github.com/Haulmont/AppletIntegration/releases but when I cal the page I have the Exception ""Widgetset does not contain implementation for org.vaadin.applet.AppletIntegration. Check its @ClientWidget mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions. Unrendered UIDL:

org.vaadin.applet.AppletIntegration(NO CLIENT IMPLEMENTATION FOUND)"
3) I create a class AppletCustom

public class AppletCustom extends CustomComponent {
    public AppletCustom(String codebase, 
            String archive, 
            String code,
            String width, 
            String height,
            Map<String, String> params) {
        setCompositionRoot(new Label("<div id='appletDiv'></div>", ContentMode.HTML));
        StringBuilder sb = new StringBuilder();
                /* create the applet */
        sb.append("var obj = document.createElement('object');");
        sb.append("obj.setAttribute('type','application/x-java-applet');");
        sb.append("obj.setAttribute('width','" + width + "');");
        sb.append("obj.setAttribute('height','" + height + "');");        
        
        sb.append("var codeParam = document.createElement('param');");
        sb.append("codeParam.setAttribute('name', 'code');");
        sb.append("codeParam.setAttribute('value', '" + code + "');");
        sb.append("obj.appendChild(codeParam);");        
        
        sb.append("var archiveParam = document.createElement('param');");
        sb.append("archiveParam.setAttribute('name', 'archive');");
        sb.append("archiveParam.setAttribute('value','" + archive + "');");
        sb.append("obj.appendChild(archiveParam);");
         
        sb.append("var param = document.createElement('param');");
        sb.append("param.setAttribute('name', 'codebase');");
        sb.append("param.setAttribute('value','" + codebase + "');");
        sb.append("obj.appendChild(param);");
        
        /* add params to the applet if you like */
        if(params != null && !params.isEmpty()){
            Iterator<Entry<String, String>> it = 
                    params.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
                sb.append("param = document.createElement('param');");
                sb.append("param.setAttribute('name', '" + pairs.getKey() + "');");
                sb.append("param.setAttribute('value','" + pairs.getValue() + "');");
                sb.append("obj.appendChild(param);");
            }
        }        
        sb.append("document.getElementById('appletDiv').appendChild(obj);");
        JavaScript.getCurrent().execute(sb.toString());
    }
    
    
}

and I Call it in the page. The applet is seen correctly but i must to return a value using the method

vaadinUpdateVariable("docName", docName + SIGNED_FILE_SUFFIX, true);

Can You help me to resolve this problem?

Hi,

Recently we migrated to latest version of vaadin (7.4). From the time we move to latest version, the applet integrated inside the window is repainting more number of times (3-5times) and also on movement of the window from one location to another location, relaunching the applet. This is happening with IE 10 and not happening with chrome.

Did anyone faced similar kind of issue and any resolution or work around found to fix it?

Following are the ways tried,

a) Overriding the paintContent method of AppletIntegration
b) Verified that the component are causing refresh because of markAsDirty made for the controls and tried by disabling
c) Verified by passing the java arguments “-Dsun.java2d.noddraw=true”

But didnt worked out and not resolved the issue. Any suggestions are welcome.

Hi every one! If someone else is interesting, I found a solution for Out of Sync error in IE. By unknown reason, when applet removes from dom, IE instantiate new instance of applet, and if applet sends updateVariable on loading then Out of Sync is rasing, because on server side AppletIntegration component does not presence any more, and in server logs we can see warning message like: “Warning: Ignoring variable change for non-existent component, VAR_PID=PID76”.

To deal with this error, need override onDetach methon in VAppletIntegration and set html to empty string:

@Override
protected void onDetach() {
    setHTML("");
    super.onDetach();
}

Thanks Pavel for exploring towards this detachment.
I have implemented the code in VAppletIntegration class. However this has not resolved the issue of re instantiate applet on closure of the window. Any other alternative or suggestion.
it will be greatful, if you can share the applet integration jar you have made to resolve this issue,

I did it for Vaadin 6 version. If I understood right, you are needed for Vaadin 7 version. I suppose, the idea is to remove the applet from the client side before the component will be removed from server side.

So, code, which I share above, is a client side code.

​I rebuilt the code with Vaadin 7.0.6 and also with latest Vaadin 7.5.0 and its working fine till IE 8. However with higher version of IE 10, IE 11, the issue of re instantiate of applet continue to exist. I have implemented the detach method provide above in the AppletIntegration JAR and also from client side to verify the scenario. the issue still exist.

Hi,

I’m trying to run a simple applet from vaadin application:
I’ve a problem with the doExecute method it’s never called as I am not getting any System.out from my applet. I tried to decompile the flow from executeCommand() to doExecute(), but I did not get doExecute call anywhere in the flow.

After running the application I am not getting any error. In console I am getting the message as print completed which is written after executeCommand() method call.
Note: If I externally instantiate my Applet as

private PCLApplet pclApplet=new PCLApplet(); and call the doExectue() method

 pclApplet.doExecute("perform-pcl-print", new String[] { pcl, EOF });

then it is working properly.

It would be great help if anybody share the solution.
Thanks in advance.
Here my code:

[code]
package com.example.vaadinappletintegrationtest;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import javax.servlet.annotation.WebServlet;
import org.vaadin.applet.AppletIntegration;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings(“serial”)
@Theme(“vaadinappletintegrationtest”)
public class VaadinappletintegrationtestUI extends UI {

          private AppletIntegration applet;
          private final VerticalLayout layout = new VerticalLayout();
          private final static String EOF = "+++EOF+++";
                        
          @WebServlet(value = "/*", asyncSupported = true)
          @VaadinServletConfiguration(productionMode = false, ui = VaadinappletintegrationtestUI.class, widgetset = "com.example.vaadinappletintegrationtest.widgetset.VaadinappletintegrationtestWidgetset")
          public static class Servlet extends VaadinServlet {
          }

          @Override
          protected void init(VaadinRequest request) {
                         layout.setMargin(true);
                         setContent(layout);

                         Button button = new Button("Click me to print PCL");
                         button.addClickListener(new Button.ClickListener() {
                                       public void buttonClick(ClickEvent event) {
                                                      executePCLPrint();
                                       }
                         });
                         layout.addComponent(button);
                         System.out.println("layout component is added."+layout);
                         applet = new AppletIntegration() {
                                      
                                       private static final long serialVersionUID = 1L;

        @Override
        public void attach() {
            setAppletArchives(Arrays.asList(new String[] {
                                       "appletintegration-1.2.10.jar",
                                       "commons-logging-1.2.jar",
                                       "commons-httpclient-3.1.jar",
                                       "commons-codec-1.10.jar",
                                       "PCLApplet.jar",
                                       "pcl.jar" }));

            setCodebase("VAADIN/applets/");
            setAppletClass("com.innowake.pclapplet.PCLApplet");
            setWidth("800px");
            setHeight("500px");
        }                             
                         };
                        
                         layout.addComponent(applet);
          }
         
          private void executePCLPrint() {
              try {
                        String[] files = new String[]

{
“C:/Users/ppr/Documents/VHINQ0.RCP”,
“C:/Users/ppr/Documents/DTL0.RCP”
};

                        String pcl = new String();
                                       for (int i = 0; i < files.length; i++) {
                                                      String fileName = files[i]

;
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
byte data = new byte[(int) file.length()]
;
fis.read(data);
fis.close();
String str = new String(data);
str += EOF;
pcl += str;
}
applet.executeCommand(“perform-pcl-print”, new String { pcl, EOF });
System.out.println(“print completed”);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

          }

}
[/code]Here is my applet code:

package com.innowake.pclapplet;
 
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import org.vaadin.applet.AbstractVaadinApplet;
public class PCLApplet extends AbstractVaadinApplet  {
              private static final long serialVersionUID = -4557388304219856607L;             
             
              @Override
    public void init() {
        super.init();
        System.out.println("Initializing PCLApplet");
        //...
    }
 
              @Override
              public void doExecute(String command, Object[] params) {
                             switch (command) {
                                           case "perform-pcl-print":
                                                          performPCLPrint((String)params[0]
, (String)params[1]
);
                                                          System.out.println("performPCLPrint completed");
                                                          break;
                             }
              }
             
              @SuppressWarnings({ "unchecked", "rawtypes" })
              private void performPCLPrint(String pclString, String eofDelimiter) {
                             System.out.println(":: eofDelimiter:"+eofDelimiter);
                             int lastPos = 0;
                             for (int i = -1; (i = pclString.indexOf(eofDelimiter, i+1)) != -1;) {
                                           final String pclContent = pclString.substring(lastPos, i);
                                           //System.out.println(":: pclString:"+pclString);
                                           final byte[] pcl = pclContent.getBytes();
                                           AccessController.doPrivileged(new PrivilegedAction() {
                                                          @Override
                                                          public Object run() {
                                                                       
                                                                        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
                                                                        DocPrintJob job = service.createPrintJob();
                                                                        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
                                                                        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
                                                                        Doc doc = new SimpleDoc(pcl, flavor, null);
                                                                        System.out.println("+++++++ PRINTING PCL START +++++++");
                                                                        System.out.println("> PCL code:");
                                                                        System.out.println(pclContent);
                                                                        try {
                                                                                      System.out.println("> Sending PCL to printer '" + service.getName() + "'");
                                                                                      job.print(doc, pras);
                                                                                      System.out.println("> Sent PCL to printer '" + service.getName() + "'");
                                                                        } catch (PrintException e) {
                                                                                      // TODO Auto-generated catch block
                                                                                      e.printStackTrace();
                                                                        }
                                                                        System.out.println("+++++++ Printing PCL END +++++++");
                                                                        return null;
                                                          }
                                           });                        
                                          
                                           lastPos = i + eofDelimiter.length();
                             }            
              }
}

Hi,

I am facing the same issue as mentioned above.
Please post the solution if any one has tried resolving this issue.

Thanks,
Mayuri