How to manipulate a javascript object in java?

Hi, I am fiddling with the java scripting interface. As I understand the rhino engine is packaged with the jdk but what I don't understand is how does one reconcile the objects one gets from their engine (e.g. sun.org.mozilla.javascript.internal.ScriptableObject) versus the ones in the rhino api (e.g. org.mozilla.javascript.ScriptableObject)?
Is the one in the jdk heavily modified or wrappered up to suit their javax.scripting interface?
More specifically, how do I manipulate javascript objects from java?
e.g. suppose I have this java code:
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine js = mgr.getEngineByName("js");
jsEngine.eval("var foo = { x : 1, y : 'hello', z : false };");
Object o = jsEngine.get("foo");Now o is instanceof sun.org.mozilla.javascript.internal.NativeObject, which is a subclass of a bunch of other classes in the s.o.m.j.i namespace. Being internal I can't use these directly.
Looking at the Rhino API obviously you normally get a org.mozilla.javascript.ScriptableObject and can call the .get() .getIds() methods. But I don't know how to translate the objects I am getting in my actual java code which uses the jdk engine into org.mozilla.javascript objects.
Is this even possible? Am I misunderstanding something completely? Should I just be using the rhino js jar and not the javax.scripting interface? If so, for what reason is the javax.scripting interface implemented?

Assuming that you DO want a deep copy, begin with a constructor that takes another hand.
public Hand( Hand h ) { ...Then for each instance variable, within that constructor:
this.instVar0 = h.instVar0;
this.instVar1 = h.instVar1;
. . .And last, for every reference, make sure there is a constructor (or copy method for arrays) that itself makes a deep copy:
this.ref0 = new Ref0Type( h.ref0 );

Similar Messages

  • Can not JavaScript objects in Java project

    Hi guys and girls,
    I have CMP managed java project that I am trying to create a menu for. Each time I create a new javascript object I am getting the error "objectname is undefined". Below is a code snipset followed by the error message I get when I try displaying the jsp.
    <head>
         <link rel="stylesheet" href="menu.css">     
         <script language="javascript" type="text/javascript" src='menu.js'></script>     
         <script language="javascript" type="text/javascript" src='menu_items.js'></script>     
         <script language="javascript" type="text/javascript" src='menu_tpl.js'></script>
    </head>
    <body leftmargin="15" rightmargin="15" marginheight="15" marginwidth="15" bgcolor="white">
    <script language="javascript">               
              new menu (MENU_ITEMS, MENU_POS);
         </script>     
    </body>
    The error message is 'menu' is undefined.
    I supspect that the src=menu.js reference is not working but I am not sure how I can change this. Any help would be appreciated.

    Hi guys and girls,
    I have CMP managed java project that I am trying to
    create a menu for. Each time I create a new javascript
    object I am getting the error "objectname is
    undefined". Below is a code snipset followed by the
    error message I get when I try displaying the jsp.
    <head>
    <link rel="stylesheet" href="menu.css">
    <script language="javascript" type="text/javascript"
    src='menu.js'></script>
    <script language="javascript" type="text/javascript"
    src='menu_items.js'></script>
    <script language="javascript" type="text/javascript"
    src='menu_tpl.js'></script>
    </head>
    <body leftmargin="15" rightmargin="15"
    marginheight="15" marginwidth="15" bgcolor="white">
    <script language="javascript">
    new menu (MENU_ITEMS, MENU_POS);
    </script>
    </body>
    The error message is 'menu' is undefined.
    I supspect that the src=menu.js reference is not
    working but I am not sure how I can change this. Any
    help would be appreciated.
    Hi
    I didn't get a clear picture of your question. Any way try this.
    1) make sure that menu.js is in the same directory as your jsp file. if it is not give the proper path.
    2) what is this MENU_ITEMS, and MENU_POS. instead of it try with integers

  • How to launch pdf javascript controls in java

    Hello,
    Here is my problem.
    We have a pdf (acroform) with controls in javascript on many fields.
    We have an xml with data to fill in the acroform.
    We made a java program, with the iText lib, to fill the pdf acroform with the xml. It's working fine, except that the javascript control are not launched. So if there is a problem in the xml, the pdf is wronlgy filled in.
    Is there a way, to launch the javascript controls in java? What library to use??
    Thank you, (sorry if my english is not good).

    Yes, it's server-side pb. The thing is, I don't really know what technology / library we can use to deal with this problem.
    If you have any idea that coul guide me...

  • How to access a javascript variable from Java?

    Here is my code:
    function validateLoginForm() {
        var username = document.getElementById('un');
        setCookie('un', username, 3650);
        //etc.
    <%   
        HttpSession httpSession = request.getSession();
        httpSession.setMaxInactiveInterval(30 * 60); //30 minutes
        httpSession.setAttribute("un", username); //!prob here - cannot resolve 'username'
    %>
    }...but how do I access the javascript variable 'username' from the Java code?
    Thanks,
    James

    The only way to pass values between JavaScript and JSP is through cookies. It sucks, I know, but right now that is the only option.
    You already are creating a cookie in JavaScript. So go ahead and read it in Java:
    Cookie[] cookies = request.getCookies();
    for(int i = 0; i < cookies.length; i++) {
        Cookie c = cookies;
    if (c.getName().equals("un")) {
    // Do what you need here.

  • How to bind a String object to java:comp/env name space?

    Hi, does anybody know how to declare a String as a JNDI object in OC4J V904. I want to register a String named 'Foo' with the value 'val' with JNDI. Eventually I want to get the value of this by referencing this JNDI name:
    java:comp/env/ejb/Foo
    I don't really care how this is done either by declaring it by way of ejb-jar.xml or a global setting at the application server level.
    Please assist!
    Thanks
    J

    There are many possible ways.
    - (BEST) Use the J2EE resource environment variable mechanism (ie resource-env-ref in ejb-jar.xml).
    - (MEDIUM) Use OC4J startup classes.
    - (IF ELSE FAILS) Use the InitialContext.rebind method.

  • How to update a Javascript Objects value in D.B

    Hello Friends,
    Can some one pass me any example pages or documentation related to using the values of HTML/Java Script objects in a PL/SQL region to update the D.B.
    Appreciate any help.
    Thanks,
    Satya.

    It works now. I made these changes:
    1. In your app process you used the column name EMP_ID instead of EMPNO
    2. In the call to your app process you used two different quotation marks for 'APPLICATION_PROCESS=GET_ENAME'
    3. In the Javascript code you used the PL/SQl notation (/* */) for comments, instead of the javascript notation (//).
    4. I changed the getElement calls to the APEX shortcuts ($v and $s). Doesn't matter much, but is way shorter!
    So the code is:
    function get_ename(){
    var emp_id = $v('P4_EMPID');
    var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=GET_ENAME',0);
    get.add('P4_EMPID',emp_id);
    var gReturn = get.get();
    $s('P4_ENAME', gReturn);
    }

  • How to manipulate Windows System Variables using Java

    Hi There,
    I want to manipulate Windows System variables (e.g. PATH, CLASSPATH) using Java program. Could anyone please let me know how it can be done in Java.
    Regards,
    Rakesh Nagar

    This is not just a Java question. It has never been possible in any Windows program to permanently change the value of an environment variable. You can only change it temporarily, and when the process that changed it ends, so does the change to the environment variable. This has been true since environment variables were added to DOS in about 1983.

  • How to add a javascript object to a library

    hi, the only way i manage is to create a subform, add the script object and adding this subform to a custom library. Then this can be used for other people by putting it in the master page and drag the script object to the variables. I wonder if there is another way to do it without using fragments because we use acrobat 7.0. Thanx in advance!

    Hello:
    You could do the following
    1)In the 'Option URL Redirect' section of the Edit Button page set 'Target is a ' to 'URL'
    2)For URL Target enter javascript:{if (confirm('Your Question here')) doSubmit('<button name>');}Varad
    Edited by: varad acharya on Jul 15, 2009 3:47 PM

  • How to copy a future object in java ???

    here is a part of class Hand for a blackjack game.
    I want to make a copy of a future Hand object using constructor copyHand(),
    I dont know how ????????
    I appreciate anyones help .....
    // the array of cards in the hand
        Card [] cards;
         * Builds a Hand with 0 cards in it, but capable of holding
         * max cards.
        public Hand(int max)
            cards = new Card[max];
         * Builds a copy of this Hand.
         * @return a deep copy of this Hand.
        public Hand copyHand()
        }-med

    Assuming that you DO want a deep copy, begin with a constructor that takes another hand.
    public Hand( Hand h ) { ...Then for each instance variable, within that constructor:
    this.instVar0 = h.instVar0;
    this.instVar1 = h.instVar1;
    . . .And last, for every reference, make sure there is a constructor (or copy method for arrays) that itself makes a deep copy:
    this.ref0 = new Ref0Type( h.ref0 );

  • How To Use A .dll Object in Java Servlet/JSP

    I need the Solution, Is there any API's Available to do so.
    Ofcourse The .dll is a Microsoft Visual Basic Product.

    You need to use JNI to wrap C/C++ function provided by the .dll library. and then call it from JNI implementation class.
    [email protected]
    http://www.sinotar.com/

  • Sending and parse javascript object variable to java variable

    can anyone help me how to send and parse javascript object variable from client to java variable on servlet. Here is what i mention about:
    suppose i have object variable var_js with it's properties:
    <script>
    var var_js = {
    id: 'var_js1',
    name: 'this is var javascript',
    allow_value_type: ['int', 'string', 'object']
    </script>
    /* after processing javascript object to java var, that i hope you guys may help me, it's java var (var_java) become something like*/
    var_java.id = "var_js1";
    var_java.name = "this is var javascript";
    var_java.allow_value_type = {"int", "string", "object"}

    You could have this html page:
    <html>
    <script>
    var var_js = {
    id: 'var_js1',
    name: 'this is var javascript',
    allow_value_type: ['int', 'string', 'object']
    function send()
    document.getElementById("id").value = var_js.id;
    document.getElementById("name").value =var_js.name;
    document.getElementById("allow_value_type").value =var_js.allow_value_type;
    document.form.submit();
    </script>
    <form name="myForm" action="http://localhost:8080/servlet/myServlet" method="post" >
    <input id="id" type="hidden" value="">
    <input id="name" type="hidden" value="">
    <input id="allow_value_type" type="hidden" value="">
    <input id="cmdGo" type="button" value="Button" onClick="send()">
    </form>
    </html>
    Then have a servlet like this:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class myServlet extends HttpServlet {
    public void doPost( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String allowed_value_type = request.getParameter("allowed_value_type");
    Var_java var_java = new Var_java(id,name,allowed_value_type);
    //and have you java object
    class Var_java
    String id;
    String name;
    String allowed_value_type;
    public var_java(String id,String name,String allowed_value_type)
    this.id=id;
    this.name=name;
    this.allowed_value_type=allowed_value_type;
    well...something like that i think.
    Hope it helps.

  • How to use bean objects in java script

    function insertRow()
              var row=1;
              var tbl = document.all("TAU");
         var tr = tbl.rows(row);
         var td = tr.cells(0);
         var td2 = tr.cells(1);
         var td3 = tr.cells(2);
         row++;
         tr = tbl.insertRow();
         tr.setAttribute(false);
         td = tr.insertCell();
         td2 = tr.insertCell();
         td3 = tr.insertCell();
         td.innerHTML = "<html:text property='unit' value ='02' />";
         td2.innerHTML = "<html:text property='unit Id' />" ;
         td3.innerHTML = "<html:text property='unit Type' />" ;
    this is my code, it is basicaly add row at run time thru java scripts. i want to set property of beans with this script , in this code i foun error ie. "can not found bean in nay scope" so plz anybody can tell me how can i pass bean object to java script !!!!!!

    mmmh i'm not understanding so much....
    well... as i told before i'm working in oracle database environment and i'm developing a java procedure.
    now, i have this object
    CREATE OR REPLACE
    TYPE REPORT.FATTURA_OBJ AS OBJECT (
    POD VARCHAR2(1000),
    ID_FATTURA NUMBER,
    ID_FILE NUMBER,
    COERENZA_EA_F VARCHAR2(1000),
    COERENZA_ER_F VARCHAR2(1000),
    COERENZA_EA_M VARCHAR2(1000),
    COERENZA_EF_M VARCHAR2(1000),
    ANOMALIA VARCHAR2(1000),
    MOTIVO_INVALIDAZIONE VARCHAR2(1000),
    MATRICOLA_CONTATORE VARCHAR2(1000),
    POTENZA_DISPONIBILE VARCHAR2(1000),
    MEMBER PROCEDURE pulisci
    /and i need to work with it inside this procedure:
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED REPORT."Manage_Excel_ASMBS" AS
    import java.io.*;
    import java.io.IOException;
    import java.io.StringWriter;
    public class Manage_Excel_ASMBS
    public static void read_Excel(String inputFile,int var_Id_Caricamento, int var_Id_Distributore, String var_Distributore) throws SQLException, IOException
              **here i need to put what i'm reading inside the excel file into oracle objects**
    /can you please give me a sample ?
    thanks

  • How to return custJava Object from Java Stored Function/Procedure to Java Application

    I WILL PAY $100 FOR SOLUTION.
    Oracle JDBC documentation gives step by step on how to return Oracle Type Object to Java Application. No question here.
    But is it possible to create Java Stored Function [getMyClass() ] which returns CUSTOM Java based object [MyClass] to Java application like:
    //java stored function
    class Foo
    public static MyClass getMyClass()
    return new MyClass();
    //java class I want to return to Java
    class MyClass
    public String getGreetings(String name)
    return "Hello " + name;
    I tried to do it using intermittent Oracle
    Type Object and OracleConnection map to make binding between Java->Oracle->Java. I could
    not get throgh meaningless run time ORA Errors. Any kind of help would be greatly
    appreciated. If you know the answer please
    post it or e-mail [email protected]
    null

    You don't say which version of the database you are on. There's an interesting looking article on OTN on handling CLOBs in JDBC in 10g. It may well be useful for earlier versions too (but no guarantees).
    Cheers, APC

  • How register COM object from java?

    Hi!
    In my user home directory I have myCOM.dll. My sign applet use this myCOM.dll. But before use this dll I must register it (by use regsvr32).When myCOM.dll will be success register my applet can work. The problem is that I can not get answer from regsvr3 (is myCOM.dll are successed registered or not, or is user has a grants to register COM object and so on.)
    Again, my java applet can work ONLY when myCOM.dll is registered.
    How I can register myCOM.dll from java applet and if registered is not success exit from java applet?

    I must not have been clear. I am not asking how to access a COM object using Java, we already have tools to do that.
    The question is whether there is a way to define a COM interface using Java. I want to code my COM object in Java. Right now we are using PowerBuilder to code COM objects. I would rather use Java.

  • Accessing JavaScript objects via JSObject

    The jaws.jar file, which contains JSObject was included in the sdk directory up to j2sdk1.4.1_05 (in j2sdk1.4.1_05\jre\lib). However, apparently this JAR file is not included in versions 1.4.2 and later versions of the sdk. So I have the following questions:
    1. Is JSObject becoming obsolete?
    2. If this is the case, what mechanism is replacing JSObject to access JavaScript objects from Java?
    Thanks for your help.

    JSObject is included in plugin.jar for Java 1.5 and 1.6, which can be found in the jdk folder unter \jre\lib
    It can be still included as usual, with:
    import netscape.javascript.JSException;
    import netscape.javascript.JSObject;
    I hope this helps.

Maybe you are looking for

  • Getting 'binary name' of the package of  a given class

    I needed this for a kind of dynamic class loader, where the binary name of the package of an object was required. What made it more complex is that the classpath of the object is not the local filesystem path, where the java executable was invoked (s

  • How to disable the FULL SCREEN option in the 'Insert Video and Audio' option

    Hi, I've been inserting some MP3's and using an image for pupils to click on to play the sound, the images are 100 pixels by 100 pixels. The only issue is that I have the grey rectangle 'Full Screen' box over the picture. This is ideal when I put vid

  • ITunes freezes when I connect my iPad2

    I recently bought an iPad2 but have not been able to sync it with iTunes yet, because every time I connect the iPad, iTunes freezes and becomes unresponsive. I use a Sony Vaio laptop with Windows 7 64-bit Professional, and the latest version of iTune

  • Trying to install Mountain Lion, getting Disk not formatted properly

    I am currently running osx 10.6.8, trying to install Mountain Lion and when I am selecting the drive to install too I get: "This disk is not formatted as Mac OS Extended (Journaled)..." This is my master HD so i cant really just reformat it? Im not g

  • Updating 6085 firmware via a Mac

    Apparently impossible as Nokia (are you listening ?)persist in turning a blind eye/deaf ear toward Mac users pleas for a Mac Suite. Feasibility of using iSync already noted though I'll need a plug in for my new 6085 - from www.media.de (whence direct