cancel
Showing results for 
Search instead for 
Did you mean: 

How to call Java method in java script function while developing portal app

Former Member
0 Kudos
1,407

Hi Friends,

I am developing one application where i need to fetch the data from KM content and displaying it on the screen in regular interval. I wrote one method in JSPdynpage for fetching data from KM content now I need to call that java method in java script function.

java method(IComponentRequest request)

{

//Coode for fetching the KM content

}

function()

{

<b>//Need to call the java method</b>

setTimeout(function, 5000);//setting the time interval for this function

}

<<htmlb display code>>

If anybody can help me in calling the java method in java script function that will be very helpful for me.

Thanks in advance,

Sandeep Bonam

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

I could able to solve the problem in other way. Thank you all for the help.

Thanks,

Sandeep Bonam.

Former Member
0 Kudos

Hi Sandeep,

how did u solve ur problem .if u give that details here it will be very useful.otherwise send it to my id given below.

tamil.venthan@gmail.com.

regards,

tamil K

Former Member
0 Kudos

Hi Tamil,

What is your exact requirement, In my case just I have given a small trail with this approach but later I resolved issue with some other way.

Thanks,

Sandeep Bonam

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

Hi Sandeep,

Please list the code you used to solve your problem. It would help others with similar issues (and those with immense curiosity).

Please resist the urge to send solutions to only one person via email.

Thanks.

Daniel

Former Member
0 Kudos

Hi Daniel,

Really I would be a helpful SDN member for all the folks in this community. Coming to this thread.... Definately I'll share the code I am using in my application with everyone. Earlier I tried to use java script and java method to fetch the content from KM and tried to refresh the page with that content.

Later I directly wrote the code to fetch content directly from thrid part sites and refreshes the page in a separate jsp file. Following is the skeleton of that

<u>XYZ.jsp</u>

import ....statements

..

...

<% String webpath =componentRequest.getWebResourcePath(); %>

//This script ensures that jsp file refreshes for every 15 minutes

java script(IPortalComponentRequest request)

{

//Gets the IFrame object

var myiframe = document.getElementById("IFrameID");

myiframe.contentWindow.location = "<%=webpath%>/<path of the jsp file>";

setTimeout(loadiframe, 900000);

}

..

..

<iframe id = "IFrameID" src="<%=webpath%>/<path of the jsp file>" name="IFrameName" marginheight="0" marginwidth="0" height="28" width="150" frameborder="0" scrolling="no">

</iframe>

...................................

<u>IFrmae.jsp</u>

<script>

setTimeout(function () {parent.loadiframe()}, 900000);

</script>

..

....

URL url = new URL("Third party website");

URLConnection connection = url.openConnection();

InputStream is = connection.getInputStream();

..

...

<Write your own logic to display the content in input stream>

Procedure Following:

1)is I am writing one IFrame.jsp file and placing all the necessary code to fetch the content from thrid part website and displaying that.

2)Wrote one Iframe tag in the main jsp file and given the IFrame.jsp as the source file, so that whatever is in the IFrame.jsp file that content will be displayed along with main jsp file.

3) Calling that iframe tag's object in the java script of main jsp file for every 15 seconds. This ensures that page refreshes.

Usage: To display the stock prices, weather reports etc..

Thanks,

Sandeep Bonam.

Former Member
0 Kudos

Hi Sandeep,

u can access java methods from javascript but there are some limitations.some browsers dont support for it.to get details refer the following links.

http://www.apl.jhu.edu/~hall/java/Java-from-JavaScript.html

http://www.derkeiler.com/Mailing-Lists/NT-Bugtraq/2003-04/0003.html

And in the link given by pankaj also they have given a note that says in IE4 or better we cant access those methods.if u find any solution for it pls give it here.

Regards,

Tamil K

Former Member
0 Kudos

Hi Sandeep ,

Both of the folks are correct refer to this gives more idea about calling java method from javascript.

http://www.rgagnon.com/javadetails/java-0170.html

thanx

Pankaj

Former Member
0 Kudos

Hi,

you can acces an applet because applet runs in the client machine.

Regards,

Beevin.

Former Member
0 Kudos

Hi,

you cannot call a java method inside a javascript function.

because javascript do not have access to server. It executes only in the client side.

Regards,

Beevin.

Former Member
0 Kudos

Hi,

I have done this, I am able to call my bean method from javascript. If you want I will send the code.

Former Member
0 Kudos

Hi,

You have to write the code in your bean and call this bean methos in your javascript method.

Here is the code to call a bean method.

<%myBean.getMethod (componentRequest)%>