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
Similar Messages
-
How to pass java arraylist into javascript arrays
Hi, i have declare an arraylist
ArrayList list1 = new ArrayList();Inside the arraylist, there are elements. Now, i wan to pass the elements in the java arraylist into javascript arrays but i encounter javascript errors.
This is how i code.
var arr1 = new Array();
<%
for ( int x =0; x<list1.size(); x++)
%>
arr1[<%=x%>] = <%=(String)list1.get(x)%>;
<%
%>how do i solve this problem?
Thanks for the guidance in advanceJTech wrote:
Hi,
Use Quotes around string value ( arr1[indexposition] = "stringvalue";), when assign to javascript array as below.
arr1[<%=x%>] = "<%=(String)list1.get(x)%>"; Regards,
Ram.Hi Ram,
How about using arr1 = <%=list.toArray()%> ??? Is this possible? I tried it but was not working on my IDE. Do you have any solutions for this??
Regards,
Thiagu -
How to pass a jsp variable into javascript??
<p><%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<p><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<p><html>
<p><c:set var="binrmapi" value="http://localhost/paas-api/bingorooms.action;jsessionid=XXXXXX?userId=TEST2&sessionId=1&key=1" />
<p><c:import var="testbinrm" url="${fn:replace(binrmapi, 'XXXXXX', jsessionid)}"/>
<p><c:set var="tuples" value="${fn:split(testbinrm, '><')}" />
<p>Time until next game
<p><c:forEach var="tuple" items="${tuples}">
<p><c:if test="${fn:contains(tuple, 'row ')}">
<p> <p><code>
<p> <c:set var="values" value="${fn:split(tuple, '=\"')}" />
<p> <font color="blue">
<p> <c:out value="${values[17]}" />
<p><c:set var="remainingtime" value="${values[17]}" />
<p> </font>
<p> </code>
<p></c:if>
<p></c:forEach>
<p><form name="counter"><input type="text" size="8" name="d2"></form>
<p><script>
<p>var milisec=0
<p>var seconds=eval("document.myForm.remaining").value;
<p>function display(){
<p> if (milisec<=0){
<p> milisec=9
<p> seconds-=1
<p>}
<p>if (seconds<=-1){
<p> milisec=0
<p> seconds+=1
<p> }
<br>else
<p> milisec-=1
<p> document.counter.d2.value=seconds+"."+milisec
setTimeout("display()",100)
<p>}
<p>display()
<p></script>
<p></body>
<p></html>
<p>This is my code that i was working on, in the jsp part of the script, i get a api call and save a value of time in the variable remainingtime.. and in the javascript, i try to have a countdown clock counting down the remaining time.. but i guess it doesnt work.. how can i get that working? thanks alot
Message was edited by:
hamham3001
Message was edited by:
hamham3001
Message was edited by:
hamham3001
Message was edited by:
hamham3001Re: How to pass a jsp variable into javascript??Here is the sameple one, hope it will solves your problem.
<html>
<body>
<form name=f>
<%!
String str = "A String"
%>
<script>
var avariable = <%=str%>
<script>
</form>
</body>
</html>
Let me know if you face any problem -
How to pass a locale object into another function?
Greetings,
i like to pass a locale object into another function. These are my code below
import java.util.*;
public class Locales{
public static void main(String[] args){
Locale locale= new Locale("EN", "US");
convert(locale);
public void convert(Locale convert)
String language = convert.getDisplayLanguage();
System.out.println(language);
}I got this error:
Locales.java:6: non-static method convert(java.util.Locale) cannot be referenced from a static content
convert(locale);
^How do i correct it?
ThanksDid you bother to do a search?
Did you bother to read any of the material that the search would have linked you to?
If you had then you would be able to understand where you are going wrong and how to fix it yourself. Instead of being spoonfed by us. -
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 -
How to pass the java object into the spring controller
Hi Friends
When I hit the url at the first time my call goes to the spring controller and sets the userDetails objects in the modelAndView.addObject("userDetails", userDetails.getUserDetails()) and returns the userDetails.html page. if I click any link in the same page i want to pass same (userDetails) object thru javascript or jquery and calls the another(controller) method and returns the same (userDetails.html) page.
It means how can i pass the java object thru javascript or jquery and calls the controller. if i get the same object in my controller i can avoid calling the db again. please help me out to resolve this issue. i am tired of fixing this issue.
Regards
Sherin PoojaIf you want to avoid calling the database again then cache the data.
However before you do that make sure that calling the database, in the context of YOUR system, is going to be an actual problem.
For example there is absolutely no point in caching a User object when only one user an hour is actually using the system. -
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 -
Passing JSP into JavaScript function
I have a database table containing a date for the end of an auction, I am able to successfully take the date from the database but I am having problems passing it and casting it to a date object within a javascript function. The purpose of the function is to begin a countdown to the passed in date. Any suggestions? The countdown function i have only works with a hard coded date object.
<SCRIPT LANGUAGE="JavaScript1.2">
mDate = new Date("October 18 2004")
function countdown(){
var now=new Date()
var diff=mDate.getTime()-now.getTime()
document.bid.days.value = Math.round(diff/(24*60*60*1000))
document.bid.hours.value = Math.round(diff/(60*60*1000))
document.bid.minutes.value = Math.round(diff/(60*1000))
document.bid.seconds.value = Math.round(diff/1000)
document.bid.mseconds.value = diff
var id=setTimeout("millenium()",1)
</SCRIPT>
<body onLoad="countdown()">
<form name="bid" method="post" action="">
<p>Timeleft</p>
<TABLE BORDER=0>
<TD width="79">Days: </TD>
<TD width="81">
<INPUT TYPE="text" NAME="days" SIZE=15></TD> <TR>
<TD width="79">Hours: </TD>
<TD width="81">
<INPUT TYPE="text" NAME="hours" SIZE=15></TD> <TR>
<TD width="79">Minutes:</TD>
<TD width="81">
<INPUT TYPE="text" NAME="minutes" SIZE=15></TD> <TR>
<TD width="79">Seconds: </TD>
<TD width="81">
<INPUT TYPE="text" NAME="seconds" SIZE=15></TD> <TR>
<TD width="79">Milliseconds:</TD>
<TD width="81">
<INPUT TYPE="text" NAME="mseconds" SIZE=15></TD> <TR>
</TABLE>
</form>
I wish to pass it as follows:
<body onLoad="countdown(<%rsProduct.get........%>)"> and then cast within the function
.............................................................................JSP.....................................................................................................
<% Connection dbConn = null;
try
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
dbConn = DriverManager.getConnection("jdbc:sybase:Tds:compserver:5000/syb3044","syb3044", "syb3044");
Statement select = dbConn.createStatement();
int ID = Integer.parseInt(request.getParameter("carId"));
ResultSet rsProduct = select.executeQuery("SELECT * FROM car WHERE carID =" + ID);
if(rsProduct.next()){}
<%
rsProduct.close();
catch (SQLException sqle)
out.println(sqle.getMessage());
catch (ClassNotFoundException cnfe)
out.println(cnfe.getMessage());
catch (Exception e)
out.println(e.getMessage());
finally
try
if(dbConn != null)
dbConn.close();
catch (SQLException sqle)
out.println(sqle.getMessage());
}%>
PLEASE NOTE THAT I AM A SECOND YEAR COMPUTER SCIENCE STUDY!
sorry if code is messy to read.
RegardsLooks like everyone's having a countdown problem.....
The script in this thread is awefully like in this one:http://forum.java.sun.com/thread.jsp?forum=45&thread=514095&tstart=0&trange=15
Anyway, there're what you can do. Write out the Date object in JSP as a Javascript Date, two ways to achieve that:
1, mydate.getTimeStamp() is should return a long value, time in millisec, so
var mDate = new Date(<%= myDate.getTimeStamp()%>);
2. a lil messy, use DateFormatter to format the sql.Date, this gives you a Date in Strint form. Do remember the exact API for the DataFormater, but something like this.
var mDate = new Date("<%= DateFormatter.format(myDate) %>");
I'd prefer the 1st approach, why changing a Date to String then just change to Date again....Also watch out the TimeZone stuff and Daylight saving time....have fun. -
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 -
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 a parameter to a javascript function
I have declared a <jsp:usebean> on my jsp to extract a flag from the request. I want to then pass this String as a parameter to a javascript function called on the body onload. What is the best way of doing this? The javascript function is embedded in the jsp - does this mean I can access the variable directly, without even passing it as a parameter? do I use the <%= > syntax to reference the String on the onload? Do I use the <bean:write> the extract the varible within he javascript. Any help appreciated....
JSP runs first on the server, and generates the HTML page with javascript.
The javascript then runs on the client - it can't call any more JSP code, without submitting a request.
In this case, you will want to use JSP to generate the javascript code that you need to run as a string on the page. You should probably use the <%= %> or the <bean:write tag>
eg
<script>
<!--
function loadForm(){
var userName = "<%= user.getName() %>";
alert("Hello " + userName);
//-->
</script>Note again. The use.getName() function will run on the server and produce static html/javascript like this
var userName = "evnafets";
JSP CODE DOES NOT RUN ON THE CLIENT. You cannot use JSP code to react to button clicks on the form for instance.
Hope this helps,
evnafets -
How to pass Application Item value in Javascript function.
Hi,
I have the following javascript in the HTML Form Element Attributes properties
I am on Page1 and passing P1_DEPT_NO page item value. This is working perferctly fine and I am able to get the exact value of the page item
onchange="javascript:function1($x('P1_DEPT_NO').value);"I am on Page1 and passing Application Item G_DEPT_NO value.
The problem here is, I am not getting the Application item value inside the javascript function.
I tried using alert(); and it's giving me value as undefined
onchange="javascript:function1($x('G_DEPT_NO').value);"Just want to know, how to pass the Application Item value in Javascript.
Thanks,
DeepakDeepak,
I am not an expert at Javascript, but the suggestin I made was because javascript is a case-sensitive language.. and therefore onChange is not the same as onchange.
Not quite sure if that is causing the problem.
Application items are not associated with a page and therefore have no user interface properties.
Therefore, as mentioned in another post, the rendering would not work for application items.
If it is for a single item, used only in this page, you could create a hidden page item and use it fo your purpose
If you still want to look at application items and AJAX, This page contains examples of using AJAX to solve problems like the one you mentioned.
http://www.oracle.com/technology/obe/hol08/apexweb20/ajax_otn.htm#t1b
Thanks,
Rajesh. -
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 advanceI 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. -
Executing java method into javascript
Hi guys, have a .jsp and I'm trying to call a metod in a class (DBCombo.class), but nothing happens in fact de <% %> simbols don't change to color red.
Is it posible to execute, assign values from javascript to java?
<script>
<!--
function fFillCmbHerr(){
if (document.frmEmpCan.cmbHerr.value == 'xx')
<% sHerrSelCmb=db.getSistOpeCmb();%>
-->
</script>
ThanxI think you are addressing the wrong Forum. Go to http://forum.java.sun.com/index.jsp and select a forum more closely related to your question.
Jane -
Transform Java Beans into XML documents?
Hi,
I have standard Java Beans (which are not generated out of XML documents), can I transform them into
XML documents even if they are not generated out of XML documents originally?
If not, is there any toll which can do that?
regards,Looks like the java.beans.XMLEncoder class is where you should start.
Maybe you are looking for
-
HTML content with images and links blocked
Hello, I very much need some help here because my company needs to send out newsletters to our clients in HTML format soon and so far the email with HTML content is being blocked as spam while text content works fine. Specifically, whenever I add a l
-
Time Out Issue in Business Objects
Hello Experts, We have around 30 WebI Reports on SAP Portal. When User logs in, it would create one connection in BOBJ, when User logs out from Portal, BOBJ is not logging out the Users, basically after 20 mins it would disconnect the connection. Is
-
Show incoming redirected calls as they are redirected on 8100?
Hi Everyone, Let me describe my problem: I have a client with a BB 8100. He also had a desktop phone with a green number on it. So it have to work like if someone is calling this green number, then the desktop phone redirects the calls to my client's
-
I blocked out my name but basically this is what i keep getting, also my internet is always one while i do this.
-
Stored text messages on SIMM card
OK, here's a question. Are text messages stored on the phones SIMM card even after they are deleted on the screen? And, if so, how can they either be retrieved or permanently deleted? Hmmmmm. I guess that's really two questions but does anyone kno