Call JavaScript method in FXML from java controller

I have fxml like
   <fx:root type="javafx.scene.Group" xmlns:fx="http://javafx.com/fxml">
    <fx:script>
        function applyState(oldState, newState)
    </fx:script>   
    ....and controller to it.
The idea is to move some view logic to fxml file.
So, when I need to change some view state, I want to call applyState from java code.
The question is how to do it.
What I have found:
We can get
fxmlLoader.getNamespace().get("applyState")and receive sun.org.mozilla.javascript.internal.InterpretedFunction.
NetBeans see this class. But while building the project i have an error
error: package sun.org.mozilla.javascript.internal does not exist
But this class really exists in rt.jar in JRE.
After that I have stopped digging into this.
I suspect that using internal API is not a good idea to call this InterpretedFunction.
Can somebody suggest how can I make such an invocation?
Edited by: 940811 on Nov 19, 2012 11:21 PM

Until JavaFX doesn't expose the ScriptEngine instance of FXMLLoader, there's no way to communicate (Java <-> Javascript) with the <fx:script>.
But, if you want to rely on a hack, you can do this:
    private ScriptEngine extractScriptEngine(FXMLLoader loader) {
        try {
            Field fse = loader.getClass().getDeclaredField("scriptEngine");
            fse.setAccessible(true);
            return (ScriptEngine) fse.get(loader);
        } catch (IllegalAccessException | NoSuchFieldException | SecurityException ex) {
            Logger.getLogger(BrowserFXController.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }

Similar Messages

  • Calling a method in view from component controller?

    Hi,
    Is it posible to call a method that is defined in the Component Controller in the View?
    If it is posible please give some sample code how to call the method?
    Regards,
    Padmalatha.K

    Padmalatha, all the methods defined in a controller from 'Methods' tab are instance methods. An instance method defined in a component controller is callable from any view controller that holds a reference to the component controller.
    Defining methods between the tags
    //@@begin others
    //@@end
    is useful if you want to declare static methods.

  • Calling native Objective C code from Java Script

    Hi,
    I want to call native objective C code from Java script.
    I know one way by using : webView:shouldStartLoadWithRequest:navigationType
    Is there another way of doing same?
    Thanks,
    Ganesh Pisal
    Vavni Inc

    Are any of those threads calling java code? If yes then are you calling the Attach method?

  • Calling a PL/SQL function from java

    I would like to call a pl/sql function from java. My pl/sql function is taking arrays of records as parameters. How do i proceed? Which specific oracle packages do I have to import?
    Please send an example.
    TIA,
    Darko Guberina

    Documentation here: http://download-uk.oracle.com/docs/cd/B14117_01/java.101/b10983/datamap.htm#sthref185
    says JPublisher can publish records too.
    But when I change the example given at http://download-uk.oracle.com/docs/cd/B14117_01/java.101/b10983/datamap.htm#sthref190 as following:
    PACKAGE "COMPANY" AS
    type emp_rec is record (empno number, ename varchar2(10));
    type emp_list is varray(5) of emp_rec;
    type factory is record (
    name varchar(10),
    emps emp_list
    function get_factory(p_name varchar) return factory;
    END;
    then I see <unknown type or type not found> at sql or java files generated. Any ideas?

  • Calling a PL/SQL Package from a controller

    Hi ,
    I have to add some busines funtionality to the standard existing oco page .
    i have extened the standard controller and add the validation logic there , now if the validation is true i have to call a pl/sql package to do some functions . now i am facing few issues here
    a) can i call a pl/sql package from a controller ?
    b) should i extend the standard AM and call the pl/sql package from the extended am . is extending am allowed ?
    please let me know the best sol to achieve this

    a) can i call a pl/sql package from a controller ?<b>Yes</b> you can call a pl/sql procedure from controller through <b>OracleCallableStatement</b> object.
    <br>
    b) should i extend the standard AM and call the pl/sql package from the extended am . is extending am allowed ?Extending AM is <b>allowed</b>, but as can achieve your goal through the CO extension, why bother to touch AM :)
    --saroj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Calling javascript method from java

    Hi this is sri,
    I have one doubt on Java Applets "how to call the javascript method from java Applet".Can u give me the complete sample code for one program(both java applet file and html file also)because i can easily understand the programming flow.
    Thanks ,
    Srilekha.

    It's an extremely important skill to learn how to search the web. Not only will it increase your research and development talents, it will also save you from asking questions that have already been answered numerous times before. By doing a little research before you ask a question, you'll show that you're willing to work and learn without needing to have your hand held the entire time; a quality that is seemingly rare but much appreciated by the volunteers who are willing to help you.
    If you've done the research, found nothing useful, and decide to post your question, it's a great idea to tell us that you've already searched (and what methodologies you used to do your research). That way, we don't refer you back to something you've already seen.
    To get you started, here's a link...
    http://www.google.com/search?q=call+java+from+javascript

  • Call Javascript methods from Java methods

    Dear All,
    I have a requirement where I need to invoke Javascript methods from a Java file located in the same machine. Are there any possible solutions for this?
    Regards,
    Alok

    Hi,
    Thanks for all your replies. Does this work on Java 5 too? Could you please share the complete code snippet which makes it work? I tried working on yours but no success.
    Regards,
    Alok

  • How call javascript method from parent window to iframe

    hi....
    i need to call javascript a method which located in iframe..
    in my java script file i used like this.
    window.frames[0].getHtml();
    it will working in IE but mozilla is not supporting
    pls help me..
    thanks
    Edited by: fsfsfsdfs on Nov 7, 2008 1:02 AM

    Sorry, Javascript is not Java and for sure not JSF.
    Repost the question at a forum devoted to Javascript.
    There are ones at [webdeveloper.com|http://www.webdeveloper.com] and [dynamicdrive.com|http://www.dynamicdrive.com].
    I can give you at most one hint: [DOM reference|https://developer.mozilla.org/en/DOM].
    Good luck.

  • Applet fails to call Javascript methods

    I'm trying to implement round-trip javascript to Java to Javascript using LiveConnect, and having a lot of trouble in Firefox. It works perfectly in IE 6. In Firefox, I can successfully call a method of an applet, and get a return value. I have not been able to get the applet to call a Javascript method. I have tried using both the call and eval methods of the JSObject with no luck. Below is my code. Any suggestions would be appreciated.
    Thanks.
    import java.applet.Applet;
    import java.awt.*;
    import netscape.javascript.*;
    public class test extends Applet {
         String message="Hello Universe!";
         JSObject proxy;
         public void paint(Graphics g) {
              g.drawString(message, 20, 20);
         // pass in ref to JS object on which to call method
         public Boolean handshake(JSObject jso) {
              proxy = jso;
              // try just calling straight eval
              proxy.eval("alert('eval')");
              // set up args object to pass to js method
              Object[] args = new Object[1];
              args[0] = "handshake";
              // call method of js object 2 different ways
              proxy.call("callback", args);
              proxy.eval("o.callback('eval')");
              return true;
         // update java display to show JS to J communication
         public void setMessage(String message) {
              this.message = message;
              repaint();
    <html>
    <head>
         <script>
              // js object to receive calls from applet
              function obj() {};
              obj.prototype = new Object();
              obj.prototype.callback = function(arg) {
                   alert("callback: " + arg);
              function doit() {
                   var a = gebi("myApplet");
                   a.setMessage("Goodbye World!");
                   o = new obj();
                   // test that js method works (it does)
                   o.callback("local");
                   // call applet method which should call back to js method
                   var there = a.handshake(o);
                   // show return value from applet method call
                   alert("there: " + there);
              window.onload = doit;
         </script>
    </head>
    <body>
         <applet
              id="myApplet"
              code="test"
              width="400"
              height="50"
              mayscript="mayscript">
         </applet>
    </body>
    </html>Results:
    In both IE and Firefox, the string shown by the applet switches to "goodbye world", the local call to the callback function works, and the call to handshake returns true.
    That's all that works in Firefox.
    In IE, the various calls to the callback method, and to the alert method of the Javascript all work.
    The results are the same whether I run the HTML page as a local file, or through IIS.
    I have also noticed that Firefox seems to hang up, crash, and just have a lot of problems dealing with this code.
    Finally, I am running all of this on XP professional SP1 with J2SE 1.5.0_04-b05 and Firefox 1.07

    Hi,
    Thanks for all your replies. Does this work on Java 5 too? Could you please share the complete code snippet which makes it work? I tried working on yours but no success.
    Regards,
    Alok

  • Calling a Page(flow logic ) from a controller

    Hi Guru's ,
        I have a senario in which I have a controller and also Page flow logic .. I want to call a page of type page flow logic from the controller ..
    I tried the below methods .. but it didnt work ..
    *navigation->goto_page('test.htm').
    DATA: r_view TYPE REF TO if_bsp_page.
    DISPATCH_INPUT( ).
    r_view = create_view( view_name = 'test.htm' ).
    call_view( r_view ).
    this works only if its is a view but not flow logic ..
    Please give ur suggesions ..
    Thanks
    Sivaraj

    hi sivaraj ,
    first refer whether u could call a page using pages with flow logic by the controller which is used in mvc design.
    may be u canot call it . u have to create a page using view according to mvc . try it once.

  • Calling a VB Com component from Java

    Hi,
    I wish to call some legacy VB 6 COM dlls from some new Java code I am writing. I was looking (just read quickly haven't tried the examples yet) at the ActiveX Bridge documentation and get the impression that it only goes one way -i.e. make Java into an ActiveX Component to be used from VB, whereas I wish to call VB from Java.
    Have I missed something or is this not the way to go to get to the legacy code?
    The legacy code also has an MIDL file. Ideally, I would love to just be able to access that from Java, but I can't find any (non-Microsoft VJ++ based) tools to help with either converting MIDL to IDL so I can use Sun's idlj.exe or just converting the MIDL to Java.
    Any pointers/tips on any of this would be appreciated.
    Thanks,
    Cheryl

    I looked at Jacob, but didn't get far either.
    Right now I'm looking at Jawin -
    http://jawinproject.sourceforge.net/jawin.html. Not
    making a lot of headway yet.
    IDL is OMG's IDL (Interface Definition Language) -
    http://www.omg.org/gettingstarted/omg_idl.htm.
    MIDL is Microsoft's version of IDL for COM - I believe
    it uses IDL., but can't seem to find a conversion
    tool.
    idlj.exe is in the bin directory of whatever JDK you
    have loaded. This tool will convert OMG IDL into Java.
    Good luck to you.Hi,
    I am facing a similar problem. I need to access a vb dll methods. I took and look at jawin and installed it.
    I want to invoke a method in the dll from my servlet.
    So do I have to create stubs for it. I opened the Type Browser that comes with jawin. It is a GUI through which I am supposed to create stub java files for that dll. But I am getting this error:
    [EXCEPTION] InfoPanel.generateInfo() failed to generated info
    org.jawin.browser.xsl.TransformationException: TransformationManager.cacheStyles
    heet() failed to compile stylesheet from: stylesheets/info/library.xsl - javax.x
    ml.transform.TransformerConfigurationException: javax.xml.transform.TransformerC
    onfigurationException: javax.xml.transform.TransformerException: java.net.Malfor
    medURLException: no protocol: stylesheets/info/library.xsl
    at org.jawin.browser.xsl.TransformationManager.cacheStylesheet(Transform
    ationManager.java:130)
    at org.jawin.browser.xsl.TransformationManager.checkStylesheet(Transform
    ationManager.java:180)
    at org.jawin.browser.xsl.TransformationManager.transform(TransformationM
    anager.java:147)
    at org.jawin.browser.info.InfoPanel.generateInfo(InfoPanel.java:68)
    at org.jawin.browser.info.InfoPanel.selectionChanged(InfoPanel.java:61)
    at org.jawin.browser.tree.TypeDataTree.fireSelectionChanged(TypeDataTree
    .java:61)
    Is anyone sucessfully able to generate stub files for the dll in jawin using Type Browser ?
    Please let me know
    my mailid is tanveerrameez(at) yahoo dot com
    thanks
    Tanveer

  • How to call sql procedure with parameter from java

    Hello,
    i am trying to call one sql procedure with two parameters from java.
    the first parameter is In parameter, the second is OUT.
    the return value of this java method should be this second parameter value.
    the following is my java code:
    protected String getNextRunNumber() {
         String runnumber=null;
         String sql = "{call APIX.FNC_SST_EXPORT.GET_NEXT_RUNNUMBER (?,?)}";
    CallableStatement state = null;
    try{
         Connection con= getDatabaseConnection();
         state = con.prepareCall(sql);
         state.setString(1, m_appKeyExport);
         state.registerOutParameter(2,Types.NUMERIC,0);
         state.execute();
    ResultSet resultR = (ResultSet)state.getObject(2);
         while (resultR.next()) {
              runnumber=resultR.getBigDecimal(1).toString();
    catch (SQLException e){System.out.println("You can not get the export next run number properly");}
    return runnumber;
    i got error message like:
    java.lang.ClassCastException: java.math.BigDecimal
    As far as i knew, if the parameter is number or decimal, we should give also the paramer scale to the method: state.registerOutParameter(), but i still get this error message.
    Please help me to solve this problem.
    Thanks a lot.

    state.execute();
    i try to use debug to find the problem, in this line, i saw
    OracleCallableStatement(OraclePreparedStatement).execute() line: 642 [local variables unavailable]
    is this the problem?

  • Invoking methods in C++ from Java

    I'm invoking the Java Virtual Machine from my C++ program like is described here: http://java.sun.com/docs/books/tutorial/native1.1/invoking/invo.html
    So, I run my C++ program (let's call it C), C invokes the JVM and starts a Java program (let's call it J). C can now invoke methods in J. Now I want J to invoke a method in C. Is this possible?

    Yes it is.
    However your C code that you want to invoke from java must be defined as "native" - that is, it is defined as the implementation for java methods that are declared native.
    The possibly most confusing part is where to put the C code and how to make the java-C linkage.
    o You can put the C code in a DLL, and use a "loadLibrary" call to make it available.
    o Alternatively, and perhaps more likely, your original C/C++program can make "registerNative" calls to the JVM to identify to it the native implementations.

  • Call native function fflush & strprn from java

    Hi,
    I need to call a native function fflush and stdprn from java for printing a file.
    How can i call this function?
    Can any one help me with sample code.
    Thanks,
    rpalanivelu

    Thanks your reply,
    Actually my problem is need to take printout using dot matrix printer(text printer) with different font size.
    So, i am using native method which is available in c.
    in c program i am using fflush,stdprn and fprintf.
    Here i've attached my sample program also.
    #include <jni.h>
    #include "NativePrint.h"
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #define MAXLINE_LEN 100
    JNIEXPORT jint JNICALL
    Java_NativePrint_dotMatrixPrint(JNIEnv* env, jobject obj )
    FILE *fp;
    char filename[20];
    char line[100]; /* A line read from the file */
    int lineNumber = 0;
    /* Print control codes */
    char boldOn = 14;
    char boldOff = 20;
    char contentlenOn = 15;
    char contentlenOff = 18;
    printf("Printing from C3");
    strcpy( filename , "sayHello.c" );
    /* Open the file in read mode */
    fp = fopen( filename , "r" );
    /* Error in opening file, then exit */
    if ( fp == NULL )
    printf( "\nERROR: %s cannot be opened\n" , filename );
    exit( 1 );
    while ( fgets( line , 100 , fp ) != NULL )
    lineNumber++; /* Line we are about to process next */
    printf("%s",line);
    /* If this is the first line */
    if ( lineNumber == 1 )
    /* then print it in bold */
    //fprintf( stdprn , "%c" , boldOn );
    fprintf( stdprn , "%c" , contentlenOn );
    fprintf( stdprn , line );
    fprintf( stdprn , "%c" , contentlenOff);
    //fprintf( stdprn , "%c" , boldOff );
    else
    /* else print it in normal mode */
    fprintf( stdprn , line );
    fflush(stdprn);
    return 0;

  • Calling existing C/C++ dll from Java Prog

    Hi,
    From within the Java code I want to use the
    functionality of an existing C API. The dll's of C are available. Is it possible to directly call the C Api using Jni or some other technique or do I need to implement a native method in C which would Use the existing C Api to get the values and Pass them to the Java prog.
    Istikhar.

    Is it possible to directly call the C Api using Jni...Depends on what you mean. You can't call it directly from java. You can use JNI, including C/C++ to call it.

Maybe you are looking for

  • Can't import photos from camera to UNIX server in Mavericks

    We have a mixed network in our office with a Windows 2008 server and a UNIX server. Before Mavericks, I was able to connect a camera or my iPhone to my MacBook Pro and download jpg files to either server. Since the upgrade to Mavericks, the files are

  • Intel GMA950 and system RAM

    I'm trying to make sense of the actual RAM used by the video system on my mini. There are some clues at http://docs.info.apple.com/article.html?artnum=303407 - but I want to dig a bit deeper... At the moment, on my mini - both vm_stat and the Activit

  • Multiple where conditions in one parameter

    Hi, Is it possible to have more than one where condition in one parameter? For example, my WHERE_CLAUSE parameter holds the value "where id='12345' and name='john smith'" when i run the report, I get a [052008_033528064][][EXCEPTION] java.lang.NullPo

  • How do i get a charge on a few thing i didnt purches on itunes

    i didnt order somthing on my itunes account what do i do? but it showed up but i dont want to pay for it.

  • Can user Reset the Password without Administrator help in MS Exchange server 2013

    Hi Team  IT is possible  for user to reset the password in MS Exchange server 2013 without Administrator help? (by getting mobile verification code how we get in Gmail ,& Outlook )    if it is possible ,kindly send me the configuration URL to my Mail