Executing a method in an applet using JavaScript

I am trying to print some information using an applet. The applet is located in the signed qds-client.jar file and has the following code:

public class PrintText extends Applet  implements Printable {

 private ClientAccount clientAccount;

 public ClientAccount getClientAccount() {
     return clientAccount;
 }

 public void setClientAccount (ClientAccount clientAccount) {
     this.clientAccount = clientAccount;
 }

 public void setClientAccountFromJSON(String json) {
     this.clientAccount = toClientAccountFromJSON(json);
     System.out.println("------------------------------SetClient");
 }

 public int print(Graphics g, PageFormat format, int page) throws
         ...
 }

 public void printText() throws PrinterException {
     ...
 }

 private String getTextToPrint(ClientAccount clientAccount) throws PrinterException {
     ...
 }

 private ClientAccount toClientAccountFromJSON(String json) {
     return JsonUtils.fromJson(ClientAccount.class, json);
 }

 public void startPrint () {
     System.out.println("------------------------------------------Start");
 }
}

The JNLP configuration looks like this:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.5+" codebase="http://localhost:10099/partials/" href="print.jnlp">
    <information>
       ....
    </information>

<resources>
    <jar href="/partials/qds-client.jar"/>
    <jar href="/partials/core-3.2.1.jar"/>
    <jar href="/partials/gson-2.3.1.jar"/>
</resources>

<applet-desc name="printText" main-class="com.qdsrest.utils.printer.PrintText" width="500" height="200"></applet-desc>

<update check="background"/>
<security>
    <all-permissions/>
</security>

Including the HTML tag for the applet:

<applet name="printApplet" jnlp_href="/partials/print.jnlp" width="10" height="10">
<param name="permissions" value="all-permissions"/>
</applet>

However, when I call a method from the applet in a JavaScript file like this:

document.printApplet.setClientAccountFromJSON({/not empty/});

I encounter the following error messages:

Error: Error calling method on NPObject!

In Mozilla and

basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.CollectionTypeAdapterFactory: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.MapTypeAdapterFactory: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter: try again ..
basic: JNLP2ClassLoader.findClass: com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory: try again ..

In Java Console. It seems that the method isn't working properly. Why am I getting "try again .." messages? What do they mean? The method toClientAccountFromJSON uses the GSON library gson-2.3.1.jar, which successfully deserializes JSON objects into Java objects. What could be causing these issues? Please advise on the correct approach.

Answer №1

Back in the days of the first browser wars, I vaguely remember a time when applets required an attribute called mayscript to communicate with javascript.

Also, don't forget that the parameter must be a string:

 setClientAccountFromJSON("somestring or stringvar");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to ensure a DOM element exists before you can start manipulating it?

In my AngularJS application, I am utilizing Angular Material and md-select. When a user clicks on the md-select, a dropdown list appears and an overlay with the tag Name is added to the DOM. My goal is to add a class or style as soon as the user clicks on ...

Exploring arrays in TestNG by utilizing the Dataprovider feature

Currently, I am engaged in Automation testing using Selenium Webdriver and the provided code is for TestNg dataprovider. Essentially, I am fetching data from an Excel sheet successfully. However, during code debugging, the TestData appears as testGoogle1(S ...

Issue with javascript code not functioning post axios request

When working on my project, I utilize axios for handling Ajax requests. I crafted a script that attaches a listener to all links and then leverages Axios to make the Ajax request. Following the Ajax request, I aim to execute some post-processing steps. Aft ...

The Firefoxdriver in Java Selenium fails to initialize when running from a .jar file

Whenever I try to execute the .jar file to initiate the firefox webdriver, I encounter an Error. Interestingly, it runs without any issues in VS-Code. SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operat ...

Vue component fails to react to updates from Vuex

Currently, I am developing a system to facilitate the management of orders at a shipping station. Although I have successfully implemented the initial changes and most of the functionality, I am encountering an issue where one component fails to update ano ...

NodeJs: Dealing with package vulnerabilities stemming from dependent npm packages - Tips for resolving the issue

Is there a way to address npm vulnerabilities that are dependent on another package? For instance, I'm encountering an error where the undici package relies on the prismix package. Things I have attempted: Executed npm audit fix Ensured Prismix is u ...

Is there a way to create an <a> element so that clicking on it does not update the URL in the address bar?

Within my JSP, there is an anchor tag that looks like this: <a href="patient/tools.do?Id=<%=mp.get("FROM_RANGE") %>"> <%= mp.get("DESCRITPION") %></a>. Whenever I click on the anchor tag, the URL appears in the Address bar. How can ...

Ways to adjust the height of one panel based on the height of surrounding panels

I have a layout with three panels: two on the left side and one on the right. <div class="row"> <div class="col s6"> <div class="panel"> content1 </div> <div class="panel"> ...

String ES6 syntax immediately after function

return pool.query`select * from mytable where id = ${value}` How can the code snippet above be rewritten in full JavaScript? I attempted to use: return pool.query(`select * from mytable where id = $(value)`) but it seems like there is a difference. Th ...

Retrieve data from a single PHP page and display it on another page

In my project, I am working with three PHP pages: index.php, fetch_data.php, and product_detail.php. The layout of my index.php consists of three columns: filter options, products panel, and detailed description. Whenever a user clicks on a product in th ...

How to apply multiple filters in JavaScript?

I have a set of objects that require filtering. If the object has an active status of true, it should always be included in the filtered result regardless of other conditions. If there is text entered for search, then the remaining items should be filter ...

Iterate through all links using a loop in Selenium

After countless attempts, I have hit my head trying to figure out how to make this work. My goal is to use Selenium to open each link one by one. However, no matter what I try, it keeps opening the first link repeatedly. The console output indicates that ...

Send a request for a multidimensional array to a PHP file using AJAX

I am in need of an array containing subarrays. Within my ProcessWire page, there are pages and subpages with various fields. I have organized this information into an array of arrays as shown below. <?php $allarticles = $pages->find("template=a ...

Restrict the quantity of recommendations provided by the AutoComplete feature

After exploring the autocomplete API from https://material-ui.com/api/autocomplete/, I am unable to figure out a way, given my basic understanding of javascript, to restrict the display of a specific number of options beneath the TextField. I am working o ...

Error in Javascript chrome when trying to determine the length of an array

I am facing an unusual issue with the JavaScript console in Chrome. When I type the following code into the console: var numbers = new Array(["/php/.svn/tmp", "/php/.svn/props"]); it returns "undefined." This leads me to believe that 'numbers' ...

Nightwatch.js feature not functioning properly in a 'closing' manner

I'm facing an issue where I need to execute a function at the beginning of my test before proceeding with the rest of the test steps. Here is the custom command I am using, named internalAdviceLinksHtml: const solr = require('solr-client') ...

Tips for Verifying Success and Error Messages from a Login Form with Selenium Automation Testing

The code snippet provided below demonstrates how to perform a G-mail login using Selenium WebDriver. package gmail_Login; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selen ...

Achieving success despite facing rejection

I am currently utilizing the bluebird settle method in order to verify results for promises without concerning myself with any rejections. Interestingly, even though I have rejected the promise within the secondMethod, the isFulfilled() still returns tru ...

Execute the function when the element comes into view

Is there a way to create a function that will automatically attach itself to an element when it comes into view? I have multiple elements on my page - element1, element2, and element3. Instead of using a large if statement, I would like to write a functio ...

What is the best way to modify a CSS property using logical operators in JQuery?

If an element with the class ".has_padding" does not have any text content, it should be set to "display:none;". However, those elements with text inside should remain visible. Below is some code where I have styled the elements to demonstrate the issue. ...