Javascript array / jsp Bean Collection
How can you fill a javascript array with the values of the collection?
<jsp:useBean id="programs" scope="request" class="java.util.Collection"/>
How can I create this array?
<script language="JavaScript" type="text/javascript">
var programData =
new Array ( new Array "${programs[1].programId}","${programs[1].programName}", "${programs[1].department}"),
new Array "${programs[2].programId}","${programs[2].programName}", "${programs[2].department}"),
</script>
I answered myself. If anyone else would like to know how to fill a javascript array with the values of a jsp beans collection.
function collectionToArray()
Array[rows] = [4];
var cnt = 0;
<c:forEach var="sp" items="${programs}">
rows[cnt][0] = ${sp.programId};
rows[cnt][1] = ${sp.programName};
rows[cnt][2] = ${sp.department};
rows[cnt][3] = ${sp.urlLink1};
rows[cnt][4] = ${sp.urlLink2};
cnt++;
</c:forEach>
}
Similar Messages
-
How to use Javascript array in the JSP
hELLO Friends,
I am creating an String array using the values
in the list of a jsp page using Java script..
How can I use this array in the same jsp
file for processing...
any help in this regard would be highly appreciated.
thanks in Advance...
ashishyou cannot pass values from javascript to JSP without having to form-post to another JSP page.
-
Assigning javascript array with jsp array
hi,
I have a jsp page where I have a array in jsp. I want to assign the values to an javascipt array. how can I do that?
the reason why I want to do this is for a perticular problem I am facing in javascript. that is....
I have a text box in my jsp page, I want the value entered in that box to be checked (whether it exists ) against a hidden string which has some value. I want that hidden string not to be shown to the user even on seeing the html source. that is why I want these values to be stored and checked against a array object of javascript.
any suggestion is appreciated
Thanks
AshutoshHai asutoshdash
if you dont mind of viewing code u can use this else dont use, its not matters weatehr user will see you code or not if the user is professiona then its a big issue normal users not think of is for this dont send valuable infos like password etc to client u may send usernames
ok to create a java array to javascript array do this (i took example of db to array ) write this inside <script> <%codes here%> </script>
var aUsername =new array();
<%
int i=0;
while (rs.next())
%>
aUsername[<%= ++i%>] = "<%= rs.getString("User_Name")%>";
<%
%>thats it use this array where ever you want in your client side(javascript ) usage
hope this will help you
archi -
How to fill a javascript array by a jsp array when the jsp is run
Hi all,
The problem i am facing is -- i want to use an javascript array in a function. The records are being fetched by jsp.
How to fill the vaules in a javascript array, which are retrieved by a jsp array
Please suggest
Thanking YouYou can use the code below:
<input type="button" value="Click Me" onclick="javascript:disp('<%= getString(str) %>')">
<%!
public String getString(String str[]){
String arrElements="";
for(int i=0;i<str.length;i++) {
arrElements+=str[i]+",";
return arrElements.substring(0,arrElements.length()-1);
%>
function disp(str) {
arr = str.split(",");
alert ("There are "+arr.length+" elements in the array");
Hope this helps. -
Jsp variables to javascript array, for loop dont work.
This works fine. con.getmake passes a different variable each time to the javascript array using a manual index.
<script>
make[0] = "<%= con.getmake() %>" ;
document.write(make[0]);
make[1] = "<%= con.getmake() %>" ;
document.write(make[1]);
make[2] = "<%= con.getmake() %>" ;
document.write(make[2]);
make[3] = "<%= con.getmake() %>" ;
document.write(make[3]);
</script>
If I try and do the same with a for loop, It seems as though all the elements hold the same first variable retrieved from con.getmake, I am not getting the next variable from my java class.
<script>
for (var i= 0; i <= 2; i++)
make[i] = "<%= con.getmake() %>" ;
document.write(make);
</script>Hi,
Java is parsed once on the server which creates a HTML page, then it is passed to the client's browser where the javascript is executed. So con.getmake() is only executed once in java. You've got to execute your loop in java not javascript :
<script>
<%
for (int i= 0; i <= 2; i++)
%>
document.write("<%= con.getmake() %>");
<%
%>
</script> -
Passing javascript parameter to bean
Here's a real short example of what I'm trying to do.
function getReport(index) {
document.write("Name = " + <%= bean.getReport(index).getName() %> );
Now of course this will not work, because my bean does not know of "index" that was passed via the javascript function. But how can I get this parameter passed? My bean holds onto a Vector of reports. My bean's method getReport(int index) will return one report. Then I can print out it's name. But I can't figure out how to pass the javascript function variable over to the java world. I want to pass the the index as a paramater when a user clicks on an option in an HTML select form.Here's a real short example of what I'm trying to do.
function getReport(index) {
document.write("Name = " + <%=
= bean.getReport(index).getName() %> );
Two options.
1) On the click, reload the page with a URL parameter &index=#
2) Copy your Report names into a javascript array for use "live" on the page.
...In JSP...
<SCRIPT LANGUAGE="JavaScript1.2">
var reportNames = new Array();
<%
int index = 0;
for(Iterator i = bean.getReports().iterator(); i.hasNext(); )
Report report = (Report)i.next();
out.print( "reportNames[" );
out.print( index++ );
out.print( "] = '");
out.print( report.getName() );
out.println("' ;" );
%>
function getReport(index) {
document.write("Name = " + reportNames[index] );
</SCRIPT>
NOTE: I use the index counter to place the objects into the array because I cannot remember the name of a javascript function that is cross-browser compatible to add to the end( might just be add ).
If you want more than one property per array location, build temporary objects with the following syntax
reportNames[0] = {name:'Here is the name', value:'avalkjd', etc:'etc'};
reportNames[0].name OR reportNames[0].etc
Hope this helps. -
Help me!! How to use JavaScript with JSP ??
I am using JDeveloper and I created a screen in JSP which uses a bean for database connectivity and retriving info onto the page.
The page has a ListBox where list items are populated from the database.My requirement is
whenever the list is changed the page shuold be refreshed with the selected item info.
I tried to use 'JavaScript' for triggering the event with 'onChange' event of the ListBox.But the event is not getting invoked. I think JavaScript is not working with JSP.
Please help me with how to Use javaScript with JSP or any other alternative where I can meet my requirement.
I have one more question...I have gone through the JSP samples in OTN and I am trying do download the sample 'Travel servlet' which show list of countries...etc
I have also gone through the 'readme' but I don't know how to extract .jar file.
I would be great if you could help me in this.
Thanks!!
Geeta
nullWe have a similar need. We have used Cold Fusion to display data from Our Oracle Database. We have a simple SElect Box in HTML populated with the oracle data. When someone selects say the State of Pennsylvania. then we have an On change event that runs a Javascript to go get all the cities in Pennsylvania.
Proble we are having is that inorder for the Javascript to work , we currently have to send all the valid data.
Do you know of any way to dynamically query the the Oracle database in Javascript -
Calling JSP bean function on button OnClick
Hi-
A NewBie question....
I have a .jsp page and supporting .java bean.
I registed the bean in .jsp page using <jsp:useBean ...>
I want to fire a function defined in that bean on the click of a button which is defined in the .jsp page
So I am doing something like this... seems like not the correct way to do since it fires this script all the time, not just when the button is clicked.
<input name='click1' type='Submit' value='Click1' onClick='<% testBean.click1Clicked (); %>'/>
Thanks for your help.Hi Kishor-
Thanks for the reply.
I realize that might be the case, as u explained in your two points.
so now I have created a hidden input field and use it's value as a way to communicate between javascript and jsp. and in bean's function I check the value of this hidden field, which will be set by the OnClick's javascript and then proceed accordingly.
Is this the correct way to accomplish what I am trying to?
Thanks again -
Unable to execute javascript from backing bean
Hello experts, I want to execute javascript function from backing bean method.
In my .jsff page, I have added the javascript as :
<jsp:root ..... >
<af:resource type="javascript" >
function fileDownloadJS() {
alert(" tesing js from backing bean");
</af:resource>
</jsp:root>
in my backing bean method :
public void callJSfuntion(ActionEvent actionEvent) {
RenderKit rk = FacesContext.getCurrentInstance().getRenderKit();
ExtendedRenderKitService erks = (ExtendedRenderKitService) Service.getService(rk, ExtendedRenderKitService.class);
erks.addScript(context, "fileDownloadJS();");
I have table in my .jsff page, inside table column, I have command link and when I click the link, I am invoking bean method :
<af:table ....>
<af:column sortProperty="title" sortable="true"
headerText="File name" width="250px" id="Title"
clientComponent="true">
<af:commandLink id="cl1" actionListener="#{MyBean.callJSfuntion}" clientComponent="true">
<af:outputText value="#{row.title}" id="ot1"/>
</af:commandLink>
</af:column>
.</table>
But when I run my taskflow and click on the link inside the table column, JS function is not invoked.
Absolutely no clue what is the issue.
Appreciate if you can help me out to resolve this issue. Thank you.For debugging purpose can you try :
<script type="javascript" >
function fileDownloadJS() {
alert(" tesing js from backing bean");
</script>
put it on top of the page and let me know what happens.
If it doesn't work try writing the function itself in your addScript(context, script); to see if it works. -
Java Vector to Javascript Array
Hi all, im facing a potential problem and would be very grateful for any help on the following
I want a Vector (rather several Vectors) comprising of serializable plain old java objects. I will have a JSP or plain HTML (probably JSP) page containing, amongst other things, a javascript array or set of arrays i want to have populated with the contents of the vectors . . .
Is this possible? not after code really just a feasible way of implementing this . . .it mi9ght turn out that it cann all be done via JSP / Java.
P.S. Asan after thought, when writing this,anyone know where i can find information regarding java accessing manipulating HTML DOM please
Thanks in advance for the help people.Cool Thanks for your replies. At least i know that it cant be done i wont look for anything on HTML DOM .....
I dont believe i didnt see that method of implementation for the vector problem it seems so straight forward .. thats what I get for being a newb at both JSP and Javascript :)
Thanks again gus much appreciated -
Storing data from resultset to javascript array
Hi all,
Can anyone let me know how to store data from servlet's result set to javascript array ?
Firstly i have downloaded all the data at client side in the resultset while the servlet form
is first loaded...then i want to use javascript array to check that whether the code entered by
the user on runtime exists in resultset or not.
If the code doesnot exist the user will be prompted to enter another code by alert.
and if the specified code exists then the name of the respective client will be displayed in
text box on the servlet form.
For this reason i want to use javascript for code validation.
Thanks for any help in advance.
sunny.vJust let JSP print it as JS array.
-
Stalling a form from loading until the initial javascript arrays are loaded
I am looking for a way to get a form to be hidden based on the onload event. I would like to call a javascript function to initially populate some select boxes based on javascript arrays, but I would like this to happen before the page loads or at least stall displaying the select boxes until they are populated.
The way it is setup now, when the page loads, the select boxes try to load first and then the rest of the form loads. I would like to know if there is a way to load the select boxes from the javascript arrays, then have the select boxes and other form elements show up at the same time. I have tried putting a <div> around the entire form and within the javascript populate function I first use "document.formname.div_id.style.visibility=hidden" then at the end of the select box population within the function, I use "document.formname.div_id.style.visiblity=visible". I tried this and the select boxes appear blank; it is as if the populate function doesn't work at all.
I realize this is a very long question, but I will award you Duke Dollars if you help me out!!!right now, I have it set up where I click on a link which is a jsp page which forwards me to the jsp page that has all the html in it. That page is where I initially try to populate the select boxes with the javscript arrays...I also have a number of javascript functions which change the contents of the select boxes based on another select box in the form. Will i have access to those "java" arrays, [instead of using the javascript arrays], that you are suggesting in the javascript code? I do need to use whatever arrays I create in javascript functions.
-
hii
I have to pass a javascript array to my java MyAction.do . So how can i do it???
Thnking YouBeing a Java newbie, I can't give you a definitive on how to pass the array to a client-side applet, although it should be possible.
As for passing it to something server-side there are only a couple ways: in a GET request on the query string or in a POST. No matter what, you will have to flatten the array with some method or other, to convert it into a text string that can be parsed on the other end.
I personally favor using hidden form elements and posting the data, because otherwise you have to worry about urlencoding your query string. You could just use javascript itself to write a series of hidden text inputs and then submit the form, so all your form handler has to do is pick up the variables.
Let's say the array is named "myarray":
Code:
+<script language="Javascript">+
document.writeln("<form name=\"myform\" method=\"POST\" action=\"myserver/myhandler.jsp\">")
for(i = 0; i < myarray.length; i+){+
document.writeln("<input type=\"hidden\" name=\"myarray[" i + "]\" value=\"" + myarray[i] + "\">")+
+}+
+document.writeln("</form>")+
+document.myform.submit()+
+</script>+
I know this is clunky and "low-tech" but it will work, and has the benefit of working for any server-side platform that can handle forms -
Hi,
I am trying to run a bean through a jsp but its giving error at useBean tag of jsp:
The error is :
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /Quadratic.jsp(7,0) The value for the useBean class attribute com.brainysoftware.Quadratic is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
My jsp is:
<HTML>
<HEAD>
<TITLE> JSP BEAN Quadratic Example </TITLE>
</HEAD>
<BODY>
<%@ page language="java" %>
<jsp:useBean id="quadratic" scope="session" class="com.brainysoftware.Quadratic" />
<jsp:setProperty name="quadratic" property="ia" param="a" />
<jsp:setProperty name="quadratic" property="ib" param="b" />
<jsp:setProperty name="quadratic" property="ic" param="c" />
X1= <%= quad.getDx1( ) %>
X2= <%= quad.getDx2( ) %>
End of program
</BODY>
</HTML>my bean is:
package com.brainysoftware;
import java.io.*;
class Quadratic{
int ia;
int ib;
int ic;
String dx1;
String dx2;
public int getIa( ) {
return ia;
public void setIa( int ii) {
ia=ii;
public int getIb( ) {
return ib;
public void setIb(int ii) {
ib=ii;
public int getIc( ) {
return ic;
public void setIc(int ii) {
ic=ii;
public String getDx1( ) {
double detA;
double result;
detA= ib*ib -4*ia*ic;
if(detA<0.0)
return "Real Roots not possible";
else {
result= -ib - Math.sqrt(detA/(2 * ia));
Double Dresult=new Double (result);
return Dresult.toString( );
public String getDx2( ) {
double detA;
double result;
detA= ib*ib -4*ia*ic;
if(detA<0.0)
return "Real Roots not possible";
else {
result= -ib + Math.sqrt(detA/(2 * ia));
Double Dresult=new Double (result);
return Dresult.toString( );
my directory structure is given below:
C:\tomcat-5.0.28\jakarta-tomcat-5.0.28\webapps\jsp-examples\WEB-INF\classes\com\
brainysoftware>dir
Volume in drive C has no label.
Volume Serial Number is 4C50-9542
Directory of C:\tomcat-5.0.28\jakarta-tomcat-5.0.28\webapps\jsp-examples\WEB-IN
F\classes\com\brainysoftware
05/22/2005 11:15 PM <DIR> .
05/22/2005 11:15 PM <DIR> ..
05/22/2005 11:18 PM 134 CalculatorBean.java
05/23/2005 12:12 AM 216 Counter.java
05/24/2005 10:48 PM 358 SimpleJavaBean.java
06/14/2005 11:16 PM 1,205 Calculator.java
06/14/2005 11:16 PM 1,323 Calculator.class
06/16/2005 06:44 PM 534 CalculatorBean2.java
06/17/2005 08:53 AM 703 CalculatorBean2.class
06/16/2005 07:00 PM 352 CalculatorBean2.html
06/17/2005 08:51 AM 588 CalculatorBean2.jsp
06/17/2005 04:29 PM 97 UploadBean.java
06/17/2005 04:43 PM 527 FileUploadBean.java
06/17/2005 04:43 PM 834 FileUploadBean.class
06/18/2005 12:21 PM 863 Quadratic.java
06/18/2005 12:21 PM 1,093 Quadratic.class
14 File(s) 8,827 bytes
2 Dir(s) 8,615,821,312 bytes free
C:\tomcat-5.0.28\jakarta-tomcat-5.0.28\webapps\jsp-examples\WEB-INF\classes\com\
brainysoftware>
The above clearly shows the presence of Bean in the reqd directory but still I am getting an error. Can somebody help me:
Zulfi.class QuadraticThe class is not public. It is only visible to other classes in the same package as itself, so the servlet (JSP) trying to instantiate and reference it can't see it.
Make it public. -
Adobe Acrobat 9: Javascript array populated combo box - Selected answer will not save
I have a combo box on one of my forms that is populated using a Javascript array. The combo box is populating just fine, but when an item is selected from that combo box, the selected item does not save when the user saves the document. Any suggestions as to what the problem is and how it can be corrected? I am a loss as to where to even begin looking. Any help is greatly appreciated.
Thank you.
LisaYou might also want to check the Scripting forum
http://forums.adobe.com/community/acrobat/acrobat_scripting
Maybe you are looking for
-
Use of New logical Level Key in OBIEE
Hi all, can anybody tell me what is the use of newlogicallevel key in hierarchies(OBIEE). why we need to set a newlogical level key for each level in hierarchies. pls explain in detail.... regards bharath
-
i made a mistake. i installed windows using boot camp without os x lion dvd. what should i do? help pls Re: can i install windows for pc on my mac or do i need the windows for mac?
-
RoboHELP HTML Freezes Different Ways
Using Windows XP and RoboHELP HTML 6.0: If I start RoboHELP HTML from the START > Programs menu, it freezes almost instantly and requires END TASK. If I double-click a previously created .xpj file in Windows Explorer view, then RH HTML starts up and
-
Report to view Production order wise atcual cost when PO is assigned to PCC
Hi All, Can anyone help me to get the report for production order wise actual cost incurred when that Production order is assigned to PCC (Product cost collector). Is it possible through Summarization hierarchy or Product drilldown? If yes, can u exp
-
Hi all , I would slit a Document in pages........ I tried Using get Text but it returns a string and i lose the character info.......... Need help thank's