on 2007 May 16 7:22 PM
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
I could able to solve the problem in other way. Thank you all for the help.
Thanks,
Sandeep Bonam.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)%>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
67 | |
11 | |
10 | |
10 | |
9 | |
9 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.