Access Java code in Javascript function
hi all,
i have a requirement where i need to access a method defined in a plain java class from a javascript function.
can anyone please let me know, who can i achieve this.
thanks in advance
I have a hyperlink in a JSP, onclick of this, i need to perform two tasks:
(1) the page should be redirected to the same page.
(2) excute a function which actually defines code to run a perl script.
so i have wrapped the function in a class and trying to call this function in the javascript function.
now i am not sure will this work.
so if there are any other alternatives to achieve this, please share.
Similar Messages
-
Can i write java code in JavaScript function
I want to call JavaBeans within JavaScript function. Can I do it?
I have a button in JSP . When the button be clicked,the data be inputted will be checked by JavaScript function. If check is ok, then call a Bean's function to write the data to database.
Please Help!well indeed u can write java code in javascript functions. But probably it will not work the way u want it to.
when u say that u click a button, it means that some client side action is performed. Now if u wud require a java bean to be called then it means that the server needs to be contacted for the same, and if that has to be done, necessarily the form needs to be submitted.
U can populate values from a java bean and then the same can be made available to a javascript variable / function when the page is loaded rather than, when the button is clicked.
What u can do is on click of button u can process [display / calulate..etc ] the information which has already been got by the java bean.
Kris -
Access Java Array in Javascript function
Hi, could someone please help me, I have an array that gets populated in java code and I need to see it in a javascript function.
Here's what I have so far:
//In java class for AvgCostChart.jsp
private String[] month;
public String[] getMonth()
{//code to populate
return month;}
Then in my javascript onLoad function I try to access it. I know how to access the values one at a time like this.
var month1='#{AvgCostChart.month[0]}';
But how do I pass this to a function.
I tried assigning to to another array to loop through the values like this:
var myArr = new Array();
myArr'#{AvgCostChart.month}';
alert (myArr[0]);
But that does not work, any one done this before.
I've also tried saving it in the session and then accessing it but can't get that to work either.
Any help will be greatly appreciated.Hi,
Please go through the following thread:
http://swforum.sun.com/jive/thread.jspa?forumID=123&threadID=60147
Hope this helps
Cheers
Girish -
Regarding use of java code inside javascript
Hi ,
I have doubt regarding how to use java code inside javascript,
i am giving my application code here
<%@page import="java.util.*"%>
<%@ page import="com.suuny.sard.pmt.pat.*"%>
<SCRIPT LANGUAGE="JavaScript">
function fun(){
var ac=document.login.Projectname.options[document.login.Projectname.selectedIndex].value;
var c = document.login.task1.value;
alert(ac);
alert(c);
return true;
</SCRIPT>
<form name="login" action="/pmt/jsp/Leavemanagement/Leave_Ems_HomePage.jsp" method="get" encType="x-www-form-encoded" >
<table width="100%" Align="Center" cellspacing="0" cellpadding="0" border="0">
<tr class="tablerow"><td colspan="6" align="center"><font class="pagehead" align="center">Create Tasks</font></td></tr>
<tr class="tableheader">
<th>Project
<th>Task-Id
<th>TaskName
<th>Assigned To
<th>description
<th>Milestone
</tr>
<%
for(int i=1;i<2;i++){%>
<tr class="tablerow"><td align="center">
<select class="SELECT" NAME="Projectname" VALUE=" " onchange="return fun();" >
<!--<option value=""> </option>-->
<%
ArrayList ar =null;
ArrayList projectids=null;
Hashtable ht = new Hashtable();
ProjectNames pnames=new ProjectNames();
ht = pnames.getProjectNames();
ar=(ArrayList)ht.get("projects");
projectids=(ArrayList)ht.get("projectIds");
for(int j=0;j<ar.size();j++){
out.println("<option value=\""+projectids.get(j)+"\">"+ar.get(j)+"</option>");
%>
</select>
<%
out.println("<td align=\"center\"><input type=\"text\" name=\"task"+i+"\"value=\"\" size=\"25\"></td>");
out.println("<td align=\"center\"><input type=\"text\" name=\"taskname"+i+"\"value=\"\" size=\"25\"></td>");
%>
<td align="center">
<select class="SELECT" NAME="Projectname1" VALUE=" ">
<!--<option value=""> </option>-->
<%
ArrayList ar1 =null;
ar1 = pnames.getProjectResource("VXML02");
for(int j=0;j<ar1.size();j++){
out.println("<option value=\""+ar1.get(j)+"\">"+ar1.get(j)+"</option>");
%>
</select>
<%
out.println("<td align=\"center\"><input type=\"text\" name=\"description"+i+"\"value=\"\" size=\"25\"></td>");
out.println("<td align=\"center\"><input type=\"text\" name=\"milestone"+i+"\"value=\"\" size=\"25\"></td><tr>");
out.println("<tr class=\"tablerow\"><td colspan=\"6\" align=\"center\"><input class=\"txtbuttonsmall\" type=\"submit\" value=\"save\"></td>");
%>
</Table>
</form>
My question is :
I selected one project from first combo box ,i need project members corresponding to the project.
In my code "pnames.getProjectResource("VXML02");" in this function iam passing one static projrct value,but i need dynamically selected project from first combo box(<select class="SELECT" NAME="Projectname" VALUE=" " onchange="return fun();" >),so please help me guys.Hi Marco,
I "executed" some java code within XSLs file. I have quoted the word executed because I didn't really run java code, but I used a simply trick that I describe you below.
Into your XSLs put an iframe which is hided (it has an height of 0 pixel). As src of the iframe put the address of a portal component which execute your code (in my case calculate some PCD URL of some pages into a defined role). As result of component execution, I use the response.write method in order to execute some jscript code, which is able to interact with the HTML generated by XSLs files, for example in my case response.write put the PCD URL into a drop down list placed into the "edit" form.
This works fine. I don't know if is suitable also for your case, anyway could be a hint, but pay attention to Roland's recommendations.
Ciao
Roberto -
Accessing java classes from javascript
Hi,
I have the following javascript function
function testjava {
var myString = new java.lang.String("Hello world"); // line 1
alert("len:"+myString.length()); // line 2
}It gives me a error at line 1 saying "'java' is undefined" in IE browser 5.5 sp2. But, both the lines execute correctly in netscape 6.
Can someone please help..
Thanks,
Vijay.It seems that IE 5.5 doesn't support accessing java classes in JavaScript, so try to install IE 6 to see if it works or maybe, you doesn't have installed propertly support for JVM in IE.
-
Setting the value of a java variable in javascript function
How can i set the value of a java variable in a javascript function?
<%
String fName = "";
%>
now i want to define a javascript function which can set the value of fName to the value it has been passed.
<script language="javascript">
function setJValue(val)
</script>
ThanksThe only way you could simulate this, would be call the same page inside the Javascript function, and send it the parameter that was passed. Then you would have your Java code retrieve this parameter by request.getParameter("value");, and set the variable accordingly.
-
Passing java parameter to javascript function in oa framework
hi all,
can anybody tell how to pass parameter to javascript function from java for example
OAMessageTextInputBean txtbean = (OAMessageTextInputBean)webBean.findChildRecursive("BuyerPrice");
String row = "rowid";
txtbean.setOnKeyUp("javascript:checkNumber("+row+")");
checknumber is javascript function defined .Hi,
go through http://forum.java.sun.com/thread.jspa?threadID=174157&messageID=539357
if ur requirement is just to pass a string to a JS function.
Thanks -
How to embid java code in JavaScript
Hi!!
I am writing JSP program.
Do u know how to embid java code in javascirpt
ex:
<SCRIPT>
alert("hello");
<%
System.out.println("Hello...Satish. ");
%>
</SCRIPT>
This alert message is not comming when i add the java code.Do u know how to embid java code in javascirptYou can't.
Java/JSP code runs, and produces a web page. At this point any html/javascript is treated just as "text" to output.
That web page is then sent to the browser which runs javascript.
All java code has been run/removed - maybe generating HTML in its place.
The only way to call java code again is to submit an HTTP request - normally by clicking a link/submitting a form. -
Pass a Java Bean into Javascript function.
Good day. Please help urgent :
I am trying to pass an instance of MyBean class into a javascript function
This code is added to the form.
private String getJavaScriptForLaunchNewComponent()
StringBuffer sb = new StringBuffer();
sb.append("<SCRIPT language='JavaScript'>");
sb.append(" function testFunction(zBean) { ");
sb.append("popAssetWinSpecs = \"left=250,top=250,width=300,height=300,scrollbars=no,toolbar=no,menubar=no,resizable=no,status=no,titlebar=no,location=no\";");
sb.append("htmlfile=\"/irj/servlet/prt/portal/prtroot/com.roche.mss.pdf.comp.PDFLauncher?zBean=\"+zBean;");
sb.append("window.open(htmlfile,\"editWindow\",popAssetWinSpecs);");
sb.append("return false;");
sb.append(" }");
sb.append("</SCRIPT>");
return sb.toString();
This code is set in the create component meth
private Component buildLink(){
GridLayout grid = new GridLayout(1,1);
grid.setCellSpacing(5);
TestBean zBean = new TestBean();
zBean.setValue("Me Now");
Link link = new Link("myLink");
link.addText("Print PDF");
link.setOnClientClick("testFunction("+zBean +")");
grid.addComponent(1,1,link);
return grid;
Is this possible ????
Thanks.solved it. Thanks
-
Access Java object from Javascript
Hi
I'm trying to invoke a Java object from Javascript (scriptengine and all that).
I want to add scripting features to a GeneXus Java generated app... and I have very basic skills on java too. Sorry for that ;o).
This is the java code to pass "params" to the scriptengine:
engine.put("remoteHandle",remoteHandle);
engine.put("context", context); The remoteHandle (int) and context (com.genexus.ModelContext) pass trough all the gx-java generated programs.
This javascript works fine:
importClass(Packages.uftestjs);
new uftestjs(remoteHandle).execute( ) ;The remoteHandle conversion is ok (javascript-number to int). The context is optional.
But if I want to pass context:
importClass(Packages.uftestjs);
new uftestjs(remoteHandle, context).execute( ) ;Fails with this:
"javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Java constructor for 'uftestjs' with arguments 'number,javax.script.SimpleScriptContext' not found."
Obviously, no conversion is possible with context (javax.script.SimpleScriptContext to com.genexus.ModelContext).
There is some way to reference de original context, by the object Id??? or something like that???
Thanks in advance for any replies!!!
Greetings from Chile. (I hope you can understand my english!)Hi
Well, since this topic is about java programming I think the place is right here.
(I use some tricks to embed java statements in genexus objects...)
I will try to get some help at Artech (GX) on how to build something... to get the conversion needed.
But they are not focussed on support this kind of questions.
Anyway, I want to know: do I can to reference an object by the objId?
I want to code something like this:
com.genexus.ModelContext context =
(com.genexus.ModelContex)getTheObjectFromTheJVM(theObjectId);(powered by google translator, ha!) -
Creating Java code for the function module
Hi Colleagues,
I have a fuction module in ABAP system. Now I want to Generate java code for the FM.
I cam to know that we can achive that using AXIS, By getting the XML file for the fuction module and generate Java
Class file using that XML file.
Can any one tell me how to achive it.
Or any other way to do that?
Please provide you valid suggestions.
Regards,
SathyaHi,
You can integrate axis2 in eclipse. I think you have to find the plugin for that.
After that you can let axis generate the jave code (stubs and proxies) for your web service via the wsdl file.
Kind Regards,
Robin -
Call Java Method From JavaScript Function
hi everyone
i need a help in calling Java method from a javaScript method
ex:
function confirmAddRecord() {
cHours =document.getElementById('frmP:ChargeHours').value;
cSTime =document.getElementById('frmP:ChargeStartTime').value;
var answer = confirm("Are you sure you want to add Record?")
if (answer){
here i want to call the Java Method that is located in session bean that takes the upper params cHours & cSTime
else{
return false;
i know i can do it as an action button but it is required me to be in that way can any one help plz
Message was edited by:
casper77That depends on the nature of your parameters. I guess you calculate the params on client and then want to submit them. In this case and if you don't want to use Ajax simple add some <input type="hidden"> elements (of course there correspondend components dependent of your framework) and store the params there. If the javascript isn't invoked by a button click, you can use a button nevertheless. Set visible="false" and call
document.getElementById('client_id_of_my_hidden_button').click();
(or maybe doClick() dependent on your framework). -
Accessing java objects through javascript
anybody know a how to get an image from java to javascript... example you get an image from a scanner through java... and then want to use it in javascript
anybody know a how to get an image from java to
javascript... example you get an image from a scanner
through java... and then want to use it in javascripthttp://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/java_js.html -
Access java from javascript in firefox
Hi,
I am trying to access java method from javascript.
It works fine with ie, but firefox somehow brings up the error
saying the method defined in java is not a function.
I am calling like.
document.applets["myapp"].soundAlarm();
I have put MAYSCRIPT in the applet tag.
still not works.
Does anyone have idea ?
ThanksTry with
document.myapp.soundAlarm();I assume that the name attribute of the APPLET is myapp.
Note the MAYSCRIPT is useless in your context. MAYSCRIPT is used when from Java you need to access the JSObject.
See http://www.rgagnon.com/topics/java-js.html for examples.
Bye. -
Calling java method from c function
Hi,
I have been through some forums and tutorials, but nothing helps me yet.
Here's my problem : I want to access java funtion from c function.
<code java>
public class MyClass {
public int oneMethod() {
return 5;
</code java>
<code c++>
void main(int argc, char *argv[]) {
// creation of JVM -> no problem
cls = (env)->FindClass("MyClass");
if (cls != 0) {
// it finds the class
mid = (env)->GetMethodID(cls, "oneMethod", "()I");
if (mid != 0) {
// it finds the method
intReturn = (env)->CallIntMethod(cls, mid);
printf("Result of oneMethod: %d \n", initReturn);
</code c++>
the initReturn gives me 0, and not 5. So what do you think the mistake is ?
Should I pass by the GetClassObject() funtion, but in this case, what object would I pass in reference since I'm using a call from c to java.
Thanks a lot for your response, and Happy new Year to all the comunity.1. You are - apparently - trying to call a method of a java object.
2. But you are instead making the call on a class.
3. You can do one of the following:
o Pass a reference to the object as you call C.
o Call some other java method (maybe static) that gets you a reference to a java object.
o Use JNI to call a java constructor to create a java object.
o Change your code to get the class object and call a static method.
Maybe you are looking for
-
Grey screen and "incorrect number of thread records"
I think I am in trouble. My eMac will not boot and gets stuck on the great screen with the Apple logo and the spinning windmill. I have followed the instructions in the Apple help article up to but not including "archive and install". I tried the adv
-
PSE 7 Editor not responding. Stuck in thinking mode for eternity...
Hoping for some help with this issue. Pleeeezee I start in Organizer, choose an image to edit, click on the quick fix (shoot in Raw), do some simple changes, then if I need more fixes I click on Open Image. The Editor window pops open and then the th
-
Why do I have to login twice after sleep mode?
Until recently I have been able to login one time with a password to get to my desktop. Now I have to login twice and I have no idea why. I am running Yosemite, whatever the newest version is. I'm not too tech savvy, but have checked every setting I
-
Import excel/csv data to oracle table problem
hello sir, i am using application importing csv/excel data to oracle table which is developed by vikas and that i want but when i add csv file and upload. My cvs file will displayed but when i click on create table button then it gives error like ...
-
Unlocking of Outbound / Inbound Queues in CRM
Hi Experts, Is there any way through which we can Unlock Outbound / Inbound Queues in bulk; which are in "READY" status in CRM. Or Is there any method to process Queues in READY / WAITING status in bulk. Thanks and regards, Amit