简体   繁体   中英

Getting a JavaObject out of a JSObject

I have a Javascript function in my xhtml page that does the following:

HTML FILE:

function getData(){
   var data = document.getElementById('data');
   return data;        
}

<input type="hidden" value="#{bean.bytes}"/>

Backing Bean Code:

public class Bean{
    public byte[] getBytes(){
       return this.bytes;
    }
}

And I have an applet that needs to get this byte array from the html Applet code:

public class TestApplet extends Applet{
   JSObject win = JSObject.getWindow(this);
   JSObject returnedValue = win.call("getData", null);
}

I've been trying to call the returnedValue.getMember("value") (fixed) ; but that gets a null value. I also tried to change the javascript to this:

HTML:

function getData(){
   var data = document.getElementById('data').value;
   return data;        
}

But that will only return me the String representation of the byte[], not the actual object.

So my question is: How do I use JSObject to get a JavaObject?

Current method gets me back a String

There is no data property.
Change it to returnedValue.getMember("value") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM