How to call java method on page load?

How to call java method on page load?
Thanks

Hey Dan,
Well, if you want to execute a java method when page is load, you need to put the clientlistener in af:document. Let me to show you an example (I can't find my post :P),
JSPX page:
<f:view>
<af:document>
<f:verbatim>
<script>
    function loadPage(event) {
        alert('Hello World!');
</script>
</f:verbatim>
<af:clientListener method="loadPage" type="load"/>
</af:document>
</f:view>If you try this code you can see that when the page has been load, you recieve the alert "Hello World!".
Furthermore, this is the javascript AJAX function that let you to call a servlet:
function ajaxFunction () {
    var httpRequest;
    if (window.XMLHttpRequest) {
        httpRequest = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        httpRequest.overrideMimeType('text/xml');
    httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
    httpRequest.open('GET', '/appname/servletname', false);
    httpRequest.send('');
function alertContents(httpRequest) {
    if (httpRequest.readyState == 4) {
        if (!httpRequest.status == 200) {
            alert('Request error. Http code: ' + httpRequest.status);
}Where 'appname' is your application name and 'servletname' is the name of the servlet that you want to call. Obviously, you can call any URL ;)
JVN

Similar Messages

  • How to execute a method after page Load?

    My question is very similar to what was discussed in following thread:
    How to execute a method after page Load?
    My requirement is that I want to run a method in backing bean of a page, immediately after the page gets loaded. In that method I want to invoke one of the method action included in the pagedef of this page, conditionally.
    I tried using the approach given in the above thread, i.e to use <f:view afterPhase="#{backing_security.setPermPriv}">, but the problem is that our page is not using 'f:view' , so I explicitly added one f:view with afterPhase property set , but it is not working, page it self is not getting loaded, it is throwing the error:
    Root cause of ServletException.
    java.lang.IllegalStateException: <f:view> was not present on this page; tag [email protected]e8encountered without an <f:view> being processed.
         at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.setProperties(UIXComponentELTag.java:108)
         at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:733)
         at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1354)
         at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.doStartTag(UIXComponentELTag.java:71)
         at oracle.adfinternal.view.faces.taglib.UIXQueryTag.doStartTag(UIXQueryTag.java:41)
         at oracle.adfinternal.view.faces.unified.taglib.UnifiedQueryTag.doStartTag(UnifiedQueryTag.java:51)
         at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:50)
         at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:262)
         at oracle.jsp.runtime.tree.OracleJspNode.execute(OracleJspNode.java:89)
         at oracle.jsp.runtimev2.ShortCutServlet._jspService(ShortCutServlet.java:89)
         at oracle.jsp.runtime.OracleJspBase.service(OracleJspBase.java:29)
         at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:665)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:387)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:822)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:746)
    Please help to resolve this issue, or am I doing anything wrong?

    Hi,
    I assume that your view is a page fragment and here - indeed - the f:view tag cannot be used. If you use ADF then one option would be to use a custom RegionController on the binding layer to listen for the render phase to invoke the method. Another option would be to use a hidden field (output text set to display="false" and have this component value referencing a managed bean property. The managed bean property's getter method can now be used to invoke the method you want to run upon view rendering
    Frank

  • How to call java method from workflow script?

    Hi
    I have a requirement of updating field value 'Document Status' based on review/approve of content from Workflow and hence need to update the version number. For that I need to call my java method from workflow during submit of review/approve condition. Please let me know how to call java method from workflow?
    Is there any alternative better way to achive this requirement from workflow? Please suggest.
    Thanks,
    Sarang

    OK. So, I think we can all conclude that you don't need to call any Java method, can't we? And, that wfUpdateMetadata is the command that will update your metadata.
    Now, the question is what are its arguments. It has two - the first is the name of a custom metadata field to be updated (let's suppose that one field is called xMinorVersion, and the other xMajorVersion), the other is the new value, e.g. <$wfUpdateMetaData("xMinorVersion", "New value.")$>As for new value - do you insist on using strings? Since you want to increase the value, it would be more convenient to work with numbers. For instance, with integers you could go with <$wfUpdateMetaData("xMinorVersion", xMinorVersion + 1)$>With strings you will need to convert it to numbers and back to strings. Besides, what happens if you have more than 100 minor versions? (you mentioned you want to add 0.01, but that would finally increase the major version, wouldn't it?) So, I think these two numbers are independent (perhaps, with exception that increase on the major version set the minor version to .00).
    If you want to present it, you can use profiles that will construct for you the representation 2.304 out of MajorVersion = 2, MinorVersion = 304
    Solved?

  • How to call java method having array as argument from c++ ?

    Hello sir,
    how to call java method having array as arguments from c++;
    here is java code which is called from c++
    class PQR {
         public void xyz(int[] ia) {
         System.out.println("hi");
              for (int i = 0; i < ia.length; i++)
                   System.out.println(ia);
    suppose all jvm invocation is done...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    For someone well versed in java, C++ and JNI although tedious that should be obvious.
    For someone not well versed in all three it is going to be very difficult.
    Even for someone that does have knowledge in all of those areas coming up with a C++ interface that reflects that functionality in a dynamic way such that anyone is will to use it is going to be quite an adventure.
    At any rate to start building it you do exactly the same thing that you would in java.
    1. Extract everything in the jar via the zip package
    2. For each found instance extract all of the methods, return types, parameters, etc and build a description tree for each class.
    Doing all of that in C++ is going to take a LOT of code. If someone wanted an estimate from me it would take me 6 months to do it. And before I would even attempt it I would get them to explain to me in detail exactly how they thought they were going to use it when I was done because I can't see any reasonable way to do that.
    I left out the description tree itself. I suppose you could duplicate the entire reflection api in C++.
    Now perhaps if it was much, much more constrained, like to only those classes that implement a single interface then that would be more reasonable.

  • How to call java method using jsp

    how to call java method using jsp.....
    anyone can help me.....i having problem here...coz i very new in java and jsp.....
    thanks.....

    keep an eye on this person's thread...they have code there and everything.
    http://forum.java.sun.com/thread.jspa?threadID=777263&tstart=0

  • How to call Java methods from a Windows application?

    Hello all,
    At our company, we need to integrate our product which is a Java Swing application with a Windows application. Specifically, we are trying to call Java methods that reside in our application from the Lotus Notes email client application, which is a native Windows application. Such that when a user clicks a button in the Lotus Notes email client, it will trigger an event in our Swing application. Is this possible using JNI? Do you know of any resources or references relating to this kind of a project?
    Thanks,
    Mete Kural

    If there is some dll interface that lets Lotus Notes load up and use a DLL, then yes, this should be possible.

  • How to call java method from C ?

    Hello,
    I try to call a native method from java which calls java method from the same class. Exception (noSuchMethodError) is thrown. Any ideas?
    Thanx in advance !
    here is the source of the native method :
    JNIEXPORT jint JNICALL Java_TestDll_Proc_1Mul_1Int_1Var_1Var_1Stdcall (JNIEnv * env, jclass jcl, jint jarg1, jint jarg2) {
    int arg1;
    int arg2;
    int arg3;
    jint res;
    char * ch = "test";
    jfieldID fid;
    jmethodID mid;
    int (* procedure) (int *, int * ,int *);
    int mch;
    arg1 = (int )jarg1;
    arg2 = (int )jarg2;
    procedure = GetProcAddress(libraryHandle,"Proc_Mul_Int_Var_Var_Stdcall");
    procedure(&arg1,&arg2,&arg3);
    res = (jint) arg3;
    printf("(*env)->GetMethodID(env, jcl, \"test\", \"()V\");\n");
    mid = (*env)->GetMethodID(env, jcl, "test", "()V");
    printf("(*env)->CallVoidMethod(env, jcl, mid);\n");
    (*env)->CallVoidMethod(env, jcl, mid);
    return res;
    here is the source of the java file:
    public class TestDll {
    static {
    System.loadLibrary("testdllwrap");
    System.out.println("java: Library testdllwrap.dll loaded");
    public TestDll() {
    public native int Proc_Mul_Int_Var_Var_Stdcall(int jarg1, int jarg2);
    public void test() {
    System.out.println("java: test()");
    public static void main(String[] args) {
    TestDll access = new TestDll();
    int a = 5;
    int b = 6;
    int c = 0;
    System.out.println("Calling Proc_Mul_Int_Var_Var_Stdcall");
    c = access.Proc_Mul_Int_Var_Var_Stdcall(a,b);
    System.out.println("Java Result = " + c);

    Something is wrong with the code you posted here.
    Since your native method is not static, it should have the jobject instance as a parameter in the function prototype, not a jclass. Also, you should be calling CallObjectMethod with a jobject, not jclass.
    Check out Jace at http://jace.reyelts.com/jace.
    To call the java method you would do:
    JNIEXPORT jint JNICALL Java_TestDll_Proc_1Mul_1Int_1Var_1Var_1Stdcall
    (JNIEnv * env, jobject jTestDll, jint jarg1, jint jarg2) {
      TestDll testDll( jTestDll );
      testDll.test();
    }God bless,
    -Toby Reyelts

  • How to call  Java method from SAPUI5 applications?

    Hi Experts,
        Please give me information that how can I call Java method or jars from SAPUI5 applications?
    Thanks,
    Nag

    Hello Nag,
    why do open this thread in BRM Space? I would suggest reopen this in "UI Development Toolkit for HTML5 Developer Center" Space.
    Regards,
    Tobias

  • How to call Java method from XSLT??

    Hi All,
    Jdev 11.1.1.3.0
    I have a requirement to implement that, I have to call Java method from XSLT. Could anyone please suggest to implement that??
    Thanks,
    Santosh M E

    As pointed by others, you must expose your method as a custom function, registering with JDeveloper (for development time) as well as with SOA Suite (for runtime).
    In the link below you will find a simple step by step example:
    https://blogs.oracle.com/reynolds/entry/building_your_own_path
    Regards,
    Luis F. Heckler

  • Very simple question: Call JavaBean method on page load?

    Someone clicks on a URL that contains parameters like: http://server/page.jsf?param=b
    How do I trigger a JavaBean method to run during page load? I see many JSF examples where JavaBean methods get called during form clicks and that works great but here I want to run code on page load.
    This must be really simple; sorry I'm new to this technology.
    Must I use <% ... %> syntax or can I use actual JSF tags or configuration to accomplish this?
    Thanks very much in advance!

    Putting a lot of logic in getter( ) function is not the best idea considering that getter( ) could be called all over the place. Using constructor for same purpose is also a bad idea especially with request scope beans. This could also happen many times at different stages. You are right, having a page load concept could be useful. Unfortunately JSF framework does not support. You could architect around it in case desperate. Or if using JSF implementation of certain vendors like IBM, you can take advantage of their implementation that was extended to support pageLoad and postBack events (similar to .NET).
    Many postings on this forum dealt with topic. Feel free to review like this one:
    http://forum.java.sun.com/thread.jspa?forumID=427&threadID=541382

  • How to call a action on page load in jsf

    Hi all,
    i am having a JSF page where i want to display the records from the datatable. I have a method in bean which call database and gets the list of records. If i call this method from a link (action on this link) present on this page i can display the records on this page.
    But i want to display these records at the time of page load only. How we can do this? How to call a action at the time of page load?
    Thanks in adv.

    If i am calling the database class and get the list in constructor only i am able to display list in the datatable on page load. This works fine. But the requirment is that if there are no records in the list display a error page with message-No records found! . But how i can navigate from the constructor to error page?
    Like-
    class MyBeam{
    MyBean{
    private List requestVOList = null;
    MyDao dao = new MyDao() //for fetching list from DB
    List records = dao.getList()  //get list from dao class
    if(records==null)
        //Navigate to error page. How to do this navigation here?
    else
        requestVOList  = records;
    //setter/getters for requestVOList 
    }

  • How to call java method in jsp file?

    can anyone guide me or teach me how can i call the java method into the jsp file? do i need a main method to call it in? or just call the method that i need 2 use only??
    below is the coding that i did. one is java and another one is jsp. hope that someone can help me on it. Thanks!!!! Really appreciate it.
    Country Method.java
    package Test;
    import java.io.File;
    import com.db4o.*;
    import com.db4o.ObjectContainer;
    import com.db4o.ObjectSet;
    public class countryMethod {
         public final static String filename = "C:\\TestStore.yap";
         public String record;
         public int value;
         public String cName1;
         private static ObjectContainer db = Db4o.openFile(filename);
         public static void storeData() {
              //Delete existing data file
              new File(filename).delete();
              //Open Database
              db = Db4o.openFile(filename);
              //Add value into database
              Country c1 = new Country(100, "Malaysia");
              Country c2 = new Country(200, "Thailand");
              Country c3 = new Country(300, "Sing");
              Country c4 = new Country(400, "Japan");
              Country c5 = new Country(500, "Indian");
              db.set(c1);
              db.set(c2);
              db.set(c3);
              db.set(c4);
              db.set(c5);
              System.out.println("abc");
         public String getData() {
              String str = "";
              try {
                   //open database
                   ObjectContainer db = Db4o.openFile(filename);
                   //Create empty object
                   Country country = new Country(0,null);
                   //Object dataset
                   ObjectSet result = db.get(country);
                   //System.out.println(result.size());
                   while(result.hasNext()){
                        Country a = (Country)result.next();
                        record = a.getName();
                        value = a.getValue();
                        str = str +" | "+ value;
                        //System.out.println(str);
                        //System.out.println(a.getValue());
              }catch(Exception s){
                   s.printStackTrace();
              str = str +" | "+ record;
              return str;
         /*public int getValue(){
              return value;
    }and the jsp.
    <%@page import com.db4o.ObjectContainer%>
    <html>
    <head><title>Testing page</titile></head>
    <body>
    <jsp:useBean id="link" class = "Test.countryMethod" />
    <%=link.getData() %>
    </body>
    </html>

    i try on the easier that i can but still i have error displaying it
    here are the files
    package com;
    public class CountryPeople {
         public String name;
         private int value;
         public CountryPeople(String name, int value){
              this.name = "Eric";
              this.value = 2;
         public String getName() {
              return name;
         public int getValue(){
              return value;
    }JSP file will be
    <html>
    <head><title>Testing page</titile></head>
    <body>
    <jsp:useBean id="store" class="com.CountryPeople"/>
    <jsp:setProperty name="store" property="name" />
    <jsp:setProperty name="store" property="value" />
    <%= store.getName() %>
    <jsp:getProperty name="store" property="name" />
    <jsp:getProperty name="store" property="value" />
    </body>
    </html>JAVA File
    <html>
    <head><title>Testing page</titile></head>
    <body>
    <jsp:useBean id="store" class="com.CountryPeople"/>
    <jsp:setProperty name="store" property="name" />
    <jsp:setProperty name="store" property="value" />
    <%= store.getName() %>
    <jsp:getProperty name="store" property="name" />
    <jsp:getProperty name="store" property="value" />
    </body>
    </html>The end message is
    the error message
    at [org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
         at java.lang.Thread.run(Unknown Source)
    Hope that you guys can me. Thanks

  • How to call java method from actionscript

    I've just now started working on Flex. May be its basic question but I’m not aware of it – how can I call a java method from actionscript. I want to call some java method on double click of a event. Can you please let me know how to proceed on this?

    OK. So, I think we can all conclude that you don't need to call any Java method, can't we? And, that wfUpdateMetadata is the command that will update your metadata.
    Now, the question is what are its arguments. It has two - the first is the name of a custom metadata field to be updated (let's suppose that one field is called xMinorVersion, and the other xMajorVersion), the other is the new value, e.g. <$wfUpdateMetaData("xMinorVersion", "New value.")$>As for new value - do you insist on using strings? Since you want to increase the value, it would be more convenient to work with numbers. For instance, with integers you could go with <$wfUpdateMetaData("xMinorVersion", xMinorVersion + 1)$>With strings you will need to convert it to numbers and back to strings. Besides, what happens if you have more than 100 minor versions? (you mentioned you want to add 0.01, but that would finally increase the major version, wouldn't it?) So, I think these two numbers are independent (perhaps, with exception that increase on the major version set the minor version to .00).
    If you want to present it, you can use profiles that will construct for you the representation 2.304 out of MajorVersion = 2, MinorVersion = 304
    Solved?

  • How to call java method from xsl

    hi friends,
    How to call a java method from xsl, i have a xsl file which will call the java method and retrieve the value and display it to the user. but its work well when i set xalan.jar and xerces.jar and the java class files in my classpath and run as
    java org.apache.xalan.xslt.Process -in navigate.xml -xsl nav-exst.xsl -HTML -out navoutpage.html[b]
    in the command prompt but when i deploy it as web application it gives error as
    [b]Namespace 'MyPack' does not contain any functions[b]

    OK. So, I think we can all conclude that you don't need to call any Java method, can't we? And, that wfUpdateMetadata is the command that will update your metadata.
    Now, the question is what are its arguments. It has two - the first is the name of a custom metadata field to be updated (let's suppose that one field is called xMinorVersion, and the other xMajorVersion), the other is the new value, e.g. <$wfUpdateMetaData("xMinorVersion", "New value.")$>As for new value - do you insist on using strings? Since you want to increase the value, it would be more convenient to work with numbers. For instance, with integers you could go with <$wfUpdateMetaData("xMinorVersion", xMinorVersion + 1)$>With strings you will need to convert it to numbers and back to strings. Besides, what happens if you have more than 100 minor versions? (you mentioned you want to add 0.01, but that would finally increase the major version, wouldn't it?) So, I think these two numbers are independent (perhaps, with exception that increase on the major version set the minor version to .00).
    If you want to present it, you can use profiles that will construct for you the representation 2.304 out of MajorVersion = 2, MinorVersion = 304
    Solved?

  • How to call java methods from different java file.

    Hi, i create 2 files:
    CircleCalculationMethod.java
    Main.java
    In Main.java, How can i call method in CircleCalculationMethod.java ?
    Should i put everything in same folder ??
    Should i do something like "import CircleCalculationMethod.java"
    Should i do something like create a package
    Thanks
    P/S: i use Eclipse software

    As I suggested in your OTHER threads - the BEST WAY to learn, and often the fastest, is to TRY THINGS yourself.
    Just posting code you get from the internet and asking others to modify it for you won't teach you anything.
    Go through The Java Tutorials. There are trails for ALL of the basic functionality that include working, sample code.
    This is the trail on 'Packages':
    Lesson: Packages (The Java™ Tutorials > Learning the Java Language)
    And this is the one on 'Classes and Objects'. This trail includes sections for methods and how to define and use them.
    Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)

Maybe you are looking for