Call static method from jsp expression
Hi, I'm using adf/bc 10.1.3.4 I'm wanting to call a static method of a class when an af:commandLink is clicked. This action attribute value for this af:commandLink would be an el expression. As an example, let's say I want to call a new static method, named test(), I've added to ADFUtils.
My af:commandLink looks like this:
<af:commandLink action="#{ADFUtils.test}" />
Obviously, this doesn't work. I can describe my actual use case if it would help. For now I'll just say that I don't want to use a managed/backing bean to house this method. How can I create a class to house this method w/o using a managed bean and adding that managed bean reference to the faces-config.xml?? Thanks, James
thanks for the interest john. i'll explain what it is i'm trying to do. I have two web applications, appA and appB, both running in the same app server instance. The apps are related in the sense that once the user logs in thru an sso mechanism, they can 'bounce' back and forth between applications. Not sure if that info is relevant, but I wanted to include it anyhow.
We've created a common banner/header jsp that we include in every page of appA and appB. Included in that header jsp is a logout link (af:commandLink), which will need to execute some code when clicked. Here is where the dilemma starts. We don't really want to have to write the code for the logout in a managed/backing bean because although both applications can use that same bean (we have it set up in the repository so that when a checkout/update is done on either appA or appB, each app, utilizing an svn external rule, would get both the banner jsp and the logout code that goes with it), making good use of the reusability concept, we would also have to add a reference to that backing/managed bean in the faces-config.xml of each application in order for it to be instantiated and used by each app. I was hoping to implement a solution which wouldn't require the developer to have to do any 'setup' on an application by application basis to use the header jsp and the code behind the Logout link. I've described a simple scenario, but in reality we'll have multiple applications, which means multiple places (faces-config.xml) where we'd need to add a reference to the managed bean which contains the logout code. It wouldn't be the end of the world for us if we ended up doing it this way, but I just have a feeling like there may be a better way to implement this so that each application's faces-config doesn't need to be touched. Hope my explanation is clear. thanks for any help you can offer.
Edited by: kcjim on Feb 25, 2009 8:21 AM
Edited by: kcjim on Feb 25, 2009 8:22 AM
Similar Messages
-
Is there anyway to call a method in Controller.jpf from a jsp page? I want to have my jsp page call a method from the jpf controller through an onChange event in the select tag. Otherwise I will have to write a large amount of javascript directly into my jsp page and really defeats the purpose of the MVC architecture. Any help is greatly appreciated. Thanks in advance.
The jsp might look something like this:
<netui:form action="DoThisOnChange">
<!--all other jsp stuff-->
<netui:select dataSource"" optionsDataSource="" onChange="this.form.submit()"/>
</netui:form>
And in JPF declare action named "DoThisOnChange" and write the logic to be done on event "onChange".
--SJ -
Calling class methods from jsp
hi - this seems like it should be painfully obvious but I am missing something somewhere and can't seem to get it to work.
The end result I am looking for is to be able to call a method similar to how I would do it in PHP or ASP.
To do this I have writte the following class (just as an example) and combpiled it to /WEB-INF/classes/com/example/util/Echo.class:
package com.example.util;
class Echo
public static void main(String[] args)
System.out.println(args[0]);
I then have a sample JSP that I attempt to use this in that looks like:
<%@ page import="com.example.util.Echo" %>
<%
RDmail("I'm using my Echo class.");
%>
My expectation would be that when I run this page in a browser, I see the text "I'm using my Echo class." printed out on the page. Instead I get the following error:
An error occurred at line: 1 in the jsp file: /classtest.jsp
Generated servlet error:
[javac] Compiling 1 source file
/var/tomcat4/work/Standalone/localhost/raindance/classtest_jsp.java:47: cannot resolve symbol
symbol : method Echo (java.lang.String)
location: class org.apache.jsp.classtest_jsp
Echo("I'm using my Echo class");
^
1 error
What am I doing wrong?Umm... I'm not entirely sure what you're attempting to do, but it looks like there's some discrepancy between your error message and your code...
RDmail("I'm using my Echo class."); in your code
and
Echo("I'm using my Echo class"); in your error message.
Is this just a cut/paste error?
Also, the main() method is only called from a command line, and will not be run when you instantiate your bean in a JSP. If you want to have your String printed out when you create a new object, you should put the print statement in the constructor. Which would then be called when you created a new object..
Echo e = new Echo("I'm using my Echo class");
Or, you could create a static method inside Echo.java that prints out the statement.
Finally, your System.out most likely will not print to your browser, but probably to a standard log, or perhaps a command window. -
Compilation error while calling static method from another class
Hi,
I am new to Java Programming. I have written two class files Dummy1 and Dummy2.java in the same package Test.
In Dummy1.java I have declared a static final variable and a static method as you can see it below.
package Test;
import java.io.*;
public class Dummy1
public static final int var1= 10;
public static int varDisp(int var2)
return(var1+var2);
This is program is compiling fine.
I have called the static method varDisp from the class Dummy2 and it is as follows
package Test;
import java.io.*;
public class Dummy2
public int var3=15;
public int test=0;
test+=Dummy1.varDisp(var3);
and when i compile Dummy2.java, there is a compilation error <identifier > expected.
Please help me in this program.public class Dummy2
public int var3=15;
public int test=0;
test+=Dummy1.varDisp(var3);
}test+=Dummy1.varDisplay(var3);
must be in a method, it cannot just be out somewhere in the class! -
Hello People!!!
I'm trying to call a method inside a viewObject from a JSP page using taglibs, but I don't know how to do this.
Anyone can help me to do this call ??
I need to pass a parameter to the method... this parameter is a column value!!
thanksAre you trying to set a whereclause? If so you can always set the whereclause as an argument to your datasource tag.. An example of this is done in the Online Orders sample app at:
http://otn.oracle.com/sample_code/products/jdev/content.html (see search_results.jsp)
In general you can use the scriptable variable that you define for your BC4J Datasource to access different BC4J methods.
Here's some code snippets showing different ways to access the BC4J Rowset (View Object) or the Application Module..
<jbo:ApplicationModule id="Mypackage3Module" definition="Project3.Mypackage3Module" releasemode="Stateful" />
<jbo:DataSource id="ds" appid="Mypackage3Module" viewobject="EmpView3" rangesize="3"/>
<%
ds.getRowSet().executeQuery();
ds.getRowSet().first();
ds.getRowSet()....(etc)
// etc..
or
ds.getApplicationModule()....(etc)
%>
JSP Codeinsight will pop up your options..
To ensure that Insight will work, make sure you have a closing scriplet marker.. "%>"...
-Chris -
Does calling class methods from bean and JSP cause collision?
Hi,
Please look at the class below:
public class X
// no member variable
public X() {}
// pay attention to static keyword
public static int getY()
Think a bean (say BeanZ) that make calls to getY() method without initializing the class X (like this: X.getY() )
And think many users having "page scope" in JSP make call to BeanZ or directly calls it from JSP.
I'm wondering if any collision occurs because of STATIC method? Should I use "SYNCHRONIZED" keyword with it? If so, what about Math.cos() which also is a non synchronized static method ? Shouldn't I use Math.cos() (and the other static methods) in JSP or bean?
Thank you for your help.
Ali SadikHi,
Thank you for your quick answer. Think my class like this:
public class X
// no member variable
public X() {}
// pay attention to static keyword
public static int[] getY(int a, int[] b)
// i know there is no need for the extra array.
// just for example ;)
int[] ret = new int[b.length];
for(int i = 0; i < b.length; i++)
ret[i] = a * b;
return ret;
Does it the type of class that you've mentioned ? It makes calculation to produce dynamic result. Shouldn't I use it as static ? If your answer is yes, what about Math.cos()? Doesn't it have dynamic calculation?
Thanks a lot. -
Hi
is it possible to call any method with in the class except handle method from jsp file?You can call , but it would not be a good design approach.A droplet can do the same task for you.
otherwise :
eg :
<%@ page import="com.mypackage.MyClass"%>
for Static access :
<%
String test= MyClass.myMethod();
%>
for normal classes :
<%
MyClass object = new MyClass();
String test= object .myMethod();
%>
http://stackoverflow.com/questions/10918526/call-java-method-in-jsp-file
http://www.javaworld.com/javaworld/jw-05-2003/jw-0523-calltag.html?page=2
```
Praveer
Edited by: Praveer Rai on Mar 26, 2013 5:08 PM -
Calling a method from a static method
hello all,
I'm calling a non-static method from a static method (from the main method). To overcome this i can make the method i am calling static but is there another way to get this to work without making the method that is being called static?
all replies welcome, thanksWhen you call a non-static method, you are saying you are calling a method on an object. The object is an instance of the class in which the method is defined. It is a non-static method, because the instance holds data in it's instance variables that is needed to perform the method. Therefore to call this kind of method, you need to get (or create an instance of the class. Assuming the two methods are in the same class, you could do
public class Foo
public static void main(String[] args)
Foo f = new Foo();
f.callNonStaticMethod();
}for instance. -
Calling a non-static method from another Class
Hello forum experts:
Please excuse me for my poor Java vocabulary. I am a newbie and requesting for help. So please bear with me! I am listing below the program flow to enable the experts understand the problem and guide me towards a solution.
1. ClassA instantiates ClassB to create an object instance, say ObjB1 that
populates a JTable.
2. User selects a row in the table and then clicks a button on the icon toolbar
which is part of UIMenu class.
3. This user action is to invoke a method UpdateDatabase() of object ObjB1. Now I want to call this method from UIMenu class.
(a). I could create a new instance ObjB2 of ClassB and call UpdateDatabase(),
== OR ==
(b). I could declare UpdateDatabase() as static and call this method without
creating a new instance of ClassB.With option (a), I will be looking at two different object instances.The UpdateDatabase() method manipulates
object specific data.
With option (b), if I declare the method as static, the variables used in the method would also have to be static.
The variables, in which case, would not be object specific.
Is there a way or technique in Java that will allow me to reference the UpdateDatabase() method of the existing
object ObjB1 without requiring me to use static variables? In other words, call non-static methods in a static
way?
Any ideas or thoughts will be of tremendous help. Thanks in advance.Hello Forum:
Danny_From_Tower, Encephalatic: Thank you both for your responses.
Here is what I have done so far. I have a button called "btnAccept" created in the class MyMenu.
and declared as public.
public class MyMenu {
public JButton btnAccept;
//Constructor
public MyMenu() {
btnAccept = new JButton("Accept");
} I instantiate an object for MyMenu class in the main application class MyApp.
public class MyApp {
private MyMenu menu;
//Constructor
public MyApp(){
menu = new MyMenu();
public void openOrder(){
MyGUI MyIntFrame = new MyGUI(menu.btnAccept);
}I pass this button all the way down to the class detail02. Now I want to set up a listener for this
button in the class detail02. I am not able to do this.
public class MyGUI {
private JButton acceptButton;
private detail02 dtl1 = new detail02(acceptButton);
//Constructor
public AppGUI(JButton iButton){
acceptButton = iButton;
public class detail02{
private JButton acceptButton;
//Constructor
public detail02(JButton iButton){
acceptButton = iButton;
acceptButton.addActionListener(new acceptListener());
//method
private void acceptListener_actionPerformed(ActionEvent e){
System.out.println("Menu item [" + e.getActionCommand( ) + "] was pressed.");
class acceptListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
acceptListener_actionPerformed(e);
} I am not able to get the button Listener to work. I get NullPointerException at this line
acceptButton.addActionListener(new acceptListener());in the class detail02.
Is this the right way? Or is there a better way of accomplishing my objective?
Please help. Your inputs are precious! Thank you very much for your time! -
Calling a static method from another class
public class Command
public static void sortCommands(String command, String order, List object)
if(command.equalsIgnoreCase("merge") && order == "a")
object.setAscending(true);
Mergesort.mergesort(object.list); // line 85
}and
public class Mergesort
public static void mergesort (int[] a)
mergesort(a, 0, a.length-1);
private static void mergesort (int[] a, int l, int r)
private static void merge (int[] a, int l, int m, int r)
}Error:
Command.java:85: cannot find symbol
symbol : variable Mergesort
location: class Command
Mergesort.mergesort(object.list)
What am I doing wrong here? Within the Command class I am calling mergesort(), a static method, from a static method. I use the dot operator + object so that the compiler would recognize the 'list' array. I tried using the
Mergesort.mergesort(object.list);notation in hopes that it would work like this:
Class.staticMethod(parameters);but either I am mistaken, misunderstood the documentation or both. Mergesort is not a variable. Any help would be appreciated, I have been hitting a brick wall for hours with Java documentation. Thanks all.[Javapedia: Classpath|http://wiki.java.net/bin/view/Javapedia/ClassPath]
[How Classes are Found|http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html]
[Setting the class path (Windows)|http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html]
[Setting the class path (Solaris/Linux)|http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html]
[Understanding the Java ClassLoader|http://www-106.ibm.com/developerworks/edu/j-dw-javaclass-i.html]
java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run. -
Calling Java Methods from Stored Procedures
Can I call Java Methods from Oracle Stored Procedures? I have a Java framework that logs events and would like to reuse it for logging events that occur in stored procedures.
nullYou need to publish java class methods to plsql.
Attached below is some information.
Although both PL/SQL modules and Java classes are stored in the database
and are managed by many of the same mechanisms, each of them resides in
its own namespace. Therefore, Java methods are not accessible from SQL
and PL/SQL by default. In order to expose Java methods to the SQL and
PL/SQL engines, first publish that Java method to the SQL namespace using
a 'Call Spec'.
Note: A 'Call Spec' does not create an additional layer of
execution so there is no performance penalty incurred.
A 'Call Spec' is simply a syntactical mechanism used to
make a method known in the SQL namespace.
The SQL name established by the 'Call Spec' can be top-level or packaged.
The syntax differs only slightly and is consistent with that used for
PL/SQL procedures and packages. For more information on the exact
syntax, see the references listed in 'Related Topics'.
In general, a top-level procedure 'Call Spec' takes the form:
CREATE OR REPLACE PROCEDURE procname ( pname mode ptype, ... )
AS LANGUAGE JAVA NAME 'javaname ( javatype, ... )';
Where: procname is the SQL name you wish to publish
pname is the name for a parameter to procname
mode is the parameter mode (i.e. IN, OUT, IN OUT)
ptype is a valid SQL type (e.g. NUMBER, CHAR, etc.)
javaname is the fully qualified name of the Java method
javatype is a Java type for the corresponding parameter
Likewise, a top-level function 'Call Spec' takes the form:
CREATE OR REPLACE FUNCTION fname ( pname mode ptype, ... ) RETURN rtype
AS LANGUAGE JAVA NAME 'javaname ( javatype, ... ) return javatype';
Where: fname is the SQL name you wish to publish
rtype is the SQL return type of the function
Note: Within the NAME clause, everything within quotes is case
sensitive. For example, if the keyword 'return' is in all
CAPS, this Call Spec will not compile.
Other optional parts of this syntax have been omitted here for simplicity.
Additional examples in subsequent sections illustrate some of these options.
eg
CREATE PROCEDURE MyProc (rowcnt IN NUMBER, numrows OUT NUMBER)
AS LANGUAGE JAVA NAME 'MyClass.MyMethod(int, int[])';
There are several important things to note here:
1.) The 'Call Spec' for a JSP must be created in the same schema as the
corresponding Java class that implements that method.
2.) IN parameters are passed by value. This is the only parameter mode
available in Java. OUT parameters, therefore, must be passed as single
element arrays in order to emulate pass by reference.
3.) Parameter names do not need to match, but the number and types of
the parameters must match (with just one exception - see item 5 below).
Oracle 8i supports conversions between an assortment of SQL and Java.
See the references listed in 'Related Topics' for additional information.
4.) Primitive types (e.g. int, float, etc.) are not required to be fully
qualified with any package name. However, standard Java object types
(e.g. String, Integer, etc.) as well as any user defined object types
(e.g. like those generated by JPublisher) must be prefixed with a
corresponding package name (e.g. java.lang) if applicable.
5.) The 'main' method which takes a single String[] parameter can be
mapped to any PL/SQL procedure or function which takes some number
of VARCHAR2 or CHAR type IN parameters. For example, the java method:
public static void main ( String[] args ) { ... }
can be mapped to each of the following:
PROCEDURE MyProc2 ( arg1 IN CHAR ) ...
PROCEDURE MyProc3 ( arg1 IN CHAR, arg2 IN VARCHAR2 ) ...
PROCEDURE MyProc4 ( arg1 IN VARCHAR2, arg2 IN VARCHAR2 ) ...
and so forth. Parameters map to the corresponding element of the String
array (e.g. arg1 -> args[0], arg2 -> args[1], etc.).
null -
Calling a method from another file
This is pretty basic stuff but i can't seem to get it right. I am calling a method from another file. The other file IS located in the same folder BUT when i compile i get errors
"cannot find symbol" <===referring to limit and sieve i believe.
The method name is "sieve" the file name is "PrimeSieve2008" and "limit" is the variable in brackets in the real method.
public static void main (String [] args) {
final int [] PRIMES;
int sieve = PrimeSieve2008.sieve(limit);
PRIMES = sieve(getValidInt());
for (int j = 0; j<PRIMES.length; j++) {
System.out.println("Prime[" + j + "] = " + PRIMES[j]);
Is "int sieve = PrimeSieve2008.sieve(limit)" the wrong way to call a file?
Thanks a million,
Alex
Edited by: Simplistic2099 on Apr 3, 2008 7:47 PM
Edited by: Simplistic2099 on Apr 3, 2008 7:49 PMSimplistic2099 wrote:
the other method runs fine:
"public static int[] sieve(final int limit){
int candidate; // possible prime
int count; // no. of primes found
boolean[] mayBePrime = new boolean[limit+1];
// remaining possibilities
final int[] PRIMES; // array to return
// initialize mayBePrime
for ( int j = 0 ; j <= limit ; j++ ) {
mayBePrime[j] = true;
mayBePrime[0] = mayBePrime[1] = false;
// apply sieve, and count primes
candidate = 2;
count = 0;
while ( candidate <= limit ) {
if ( mayBePrime[candidate] ) {
count++;
for ( int j = 2 * candidate ; j <= limit ; j += candidate ) {
mayBePrime[j] = false;
} // end for
} // end if
candidate++;
} // end while
// fill up new array with the primes found
PRIMES = new int[count];
count = 0;
for (int j = 2 ; j <= limit ; j++ ) {
if ( mayBePrime[j] ) {
PRIMES[count] = j;
count++;
} // end if
} // for
return PRIMES;
} // sieve
I really am clueless here.in this one you are passing in limit.
in the other one you are getting limit from somewhere outside of main. -
Calling a method from another class or accessing a component from another
Hi all
im trying to make a find/replace dialog box
my main application form has a jtextpane and when i open up the find and replace dialog box it has two textboxes (find and replace)
now i have the code to do the finding on my jtextpane but how do i call that code to do the find method?
I have tried having the code in my main application class but then how do i call that method from my dialog box class?
ive also tried having the code in my dialog box class, but then how to i tell it to work on my jtextpane which is in my main ap class?well if someone had been nice enough to provide me
with a tutorial i wouldnt have gotten into this
muddle, no need to be rude is there!I'm not rude. And you also wouldn't have gotten into the muddle if you searched yourself. This site provides many very good tutorials about all kinds of stuff.
http://java.sun.com/docs/books/tutorial/java/javaOO/classes.htmlAmong other things, it mentions that "static" defines everything that belongs to a class, as opposed to an object. -
Can anyone help??
I'm trying to call a webservice from within a JSP and i havent a clue how its done,
i have my IF and Impl and Client Coded and my stubs generated and service deployed and running, but i cannot figure out how to call the service from my JSP web-app.
Any help appreciated!Hi ,
Its easy to call a WS from jsp what you can do is this. Think in manner that u will be keeping the client classes on a particular container, then in same container you can refrence the classes and can invoke service through a jsp..this works in my case.. it depends what kind of client do u want to create may be static or proxy or DII -
How to Call C++ Method from Java
I need to call C++ method from Java.
I have gone through the JNI tuorial , but was not able to pin point things.
I read that :
You have to write JNI c functions which then call your C++ member functions.You need to write a JNI function which will call new on your C++ class.
Now i have java class :
Java Code JavaClass.java ---->
class JavaClass{
public native void nativeMethod();
static
System.loadLibrary("NativeCppCode");
private void callCppMethod()
//call C++ method
JavaClass jvc = new JavaClass();
jvc.nativeMethod()
}Cpp Code:
NativeCppCode.h---->
class NativeCppCode
public:
getValue();
setValue();
private:
int a;
JNIEXPORT void JNICALL Java_JavaClass_nativeMethod(JNIEnv *env
,jobject obj);NativeCppCode.C---->
NativeCppCode::getValue()
return a;
NativeCppCode::setValue()
a = 1;
JNIEXPORT void JNICALL Java_JavaClass_nativeMethod(JNIEnv *env
,jobject obj)
NativeCppCode* nativeInstabce = new NativeCppCode();
NativeCppCode.setValue();
}Is this the correct way to do it.
Any suggestion would be a great help to metryit wrote:
I need to call C++ method from Java.Not possible.
JNI uses C methods.
Is this the correct way to do it.Same way you would do it in any C/C++ method (not java)
MyClass* p = ....
p->doit();
Common idiom for the pointer in the above is to pass it back and forth to your java code as a java long. You cast it it and from your class pointer. Provide an explicit java method to free it when done. Besides providing the explicit method also implement a finalizer to free it as well (however that is a fail safe and should not be relied upon.)
Maybe you are looking for
-
I have an IPod Touch that has been formatted for a Mac. All instructions I have been able to find use ITunes or Device Manager to reformat the device for Windows. This cannot be done if Windows doesn't recognize the device. Is there another way to
-
Hi All, My users want to be able to create a payment proposal, then execute a report of the payment proposal which can be exported nicely to excel. The reason for this is that they have a budget for the payment so they create a proposal, then block
-
Lightbox Slideshows in Muse-.
Hello People, I am trying to create the 'work' section of my website in Muse. (which up until this point has been great!) I have created a range of rollover images for the different projects starting out black & white and turning colour on rollover.
-
I can`t activate Iphone 4s after wipe out
Hi, I changed my password to log into iphone4s and I blocked it. Earlier I`d installed FindMyIphone. I tried to erase data hoping that i could restart it. I also erased Iphone from findmyiphone. Now i Try to activate it and every time I try, connecti
-
Hi guys, What is the transaction for starting BEX in BW , or how do i open it? Thanks