Solved

Passing varray elements(from JSP) to an array in javascript

Posted on 2004-04-13
11
326 Views
Last Modified: 2008-02-01
Dear All,

I am supposed to display a menu which has sub - menus. The no of menus and sub - menus have to decided at run - time i.e. the entire data has to be populated from a table in a database.

One way of doing it can be getting the data into a varray from the table and then passing it to an array in javascript. Now, is it possible to pass a varray (from a JSP) to an array in javascript.

If this is possible then i need the code as early as possible.It's on an urgent basis.

Plz help

Regards

Nikhil Bansal
0
Comment
Question by:nikhilbansal
  • 3
  • 3
  • 2
  • +1
11 Comments
 
LVL 7

Expert Comment

by:searlas
ID: 10811991
You cannot 'pass' an array from JSP to JavaScript, but I think what you need to do is quite simple:

In your JSP

<script type="text/javascript">
var javascriptArray = [
<% for (int i = 0; i < jspArray.length; i++) { %>
<%= i == 0 ? "" : ", " %> '<%= jspArray[i] %>'
<% } %>
];
</script>
0
 
LVL 1

Author Comment

by:nikhilbansal
ID: 10812292
Dear All,

I have made a mistake in my question. Instead of vector I have written varray. This might be quite confusing.

I feel sorry for it. Actually I have been working on PL SQL  and Java and so I made this mistake.

Regards

Nikhil Bansal
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10812418
Vector does not help. It is absolutely of no use. The vector value is valid only in the database access context. At next call it does not have no meaning in new process and new storage.

How did you want to reuse that vector pointer? What do you want to achieve? Could you use some record counter?

0
 
LVL 7

Expert Comment

by:searlas
ID: 10813288
<script type="text/javascript">
var javascriptArray = [
<% for (int i = 0; i < vector.size(); i++) { %>
<%= i == 0 ? "" : ", " %> '<%= vector.get(i) %>'
<% } %>
];
</script>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

by:mreuring
ID: 10813674
I would like to raise one question:
 - Why not use jsp to build an html-based menu, using one of many good css-powered menu's?
0
 
LVL 1

Author Comment

by:nikhilbansal
ID: 10824880
Hi Zvonko

Cud u plz visit the site  http://www.softcomplex.com/products/tigra_menu/ and go there to the menu. There you can see below "Overview" a menu having "Menu Compatibility" etc. When i position my mouse over Menu Compatibility then it cascades to Supported Browsers,  Unsupported Browsers and Report Test Results.

Now for developing such a menu, they have hard - coded everything. I want it to be dynamic in nature.

My only question is tht can this dynamism be achieved for developing such a menu and if yes, then how ???

Plz visit the link provided as it will make the picture clearer.

Regards
Nikhil
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10825111
I see that their demo/menu_items.js is highly structured and can be produced by your server side scripting as well.
And it need not to be placed outside the page in an extra file. You can embed your menu structure in a <script> section on your page.

0
 
LVL 1

Author Comment

by:nikhilbansal
ID: 10832051
Dear Zvonko

I visited the link http://www.likno.com/examples/example3.html. They are having a horizontal sub - menu.

I tried developing tht but cudn't succeed.

Cud u plz help.

I want the code which gives a horizontal sub - menu

Regards
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
ID: 10832529
Again, I got running that  example on my PC, so all I can say is that you have to dynamicaly create this file content:
http://www.likno.com/examples/example3.js

But beside that menu structure script you need some driver scripts and some gifs in defined directory positions.

I hope you do not understand this question like "how to crack a menu product", or do you still ask how to paste html code with JavaScript content into your page?
You have to produce this script dynamicaly on your page to get upper example3.html running:
<script>
//----------DHTML Menu Created using AllWebMenus PRO ver 3.1-#514---------------
var awmMenuName='example3';
var awmLibraryPath='/../awmData-menu';
var awmImagesPath='/example_images';
var awmSupported=(navigator.appName + navigator.appVersion.substring(0,1)=="Netscape5" || document.all || document.layers || navigator.userAgent.indexOf('Opera')>-1)?1:0;
if (awmAltUrl!='' && !awmSupported) window.location.replace(awmAltUrl);
if (awmSupported){
var awmMenuPath;
if (document.all) mpi=document.all['awmMenuPathImg-example3'].src;
if (document.layers) mpi=document.images['awmMenuPathImg-example3'].src;
if (navigator.appName + navigator.appVersion.substring(0,1)=="Netscape5" || navigator.userAgent.indexOf('Opera')>-1) mpi=document.getElementById('awmMenuPathImg-example3').src;
awmMenuPath=mpi.substring(0,mpi.length-16);
while (awmMenuPath.search("'")>-1) {awmMenuPath=awmMenuPath.replace("'", "&#39;");}
var nua=navigator.userAgent,scriptNo=(nua.indexOf('Safari')>-1)?7:(nua.indexOf('Gecko')>-1)?2:((document.layers)?3:((nua.indexOf('Opera')>-1)?4:((nua.indexOf('Mac')>-1)?5:((nua.indexOf('Konqueror')>-1)?6:1))));
prompt("<SCRIPT SRC='",awmMenuPath+awmLibraryPath+"/awmlib"+scriptNo+".js");
document.write("<SCRIPT SRC='"+awmMenuPath+awmLibraryPath+"/awmlib"+scriptNo+".js'><\/SCRIPT>");
var n=null;
awmzindex=1000;
}

var awmSubmenusFrame='';
var awmSubmenusFrameOffset;
var awmOptimize=0;
function awmBuildMenu(){
if (awmSupported){
awmImagesColl=['grey_arrow_right.gif',10,10,'grey_arrow_right_over.gif',10,10,'grey_arrow_down.gif',7,10,'grey_arrow_down_over.gif',10,10];
awmCreateCSS(1,2,1,'#FFFFFF','#000000',n,'14px sans-serif',n,'none',2,n,5,4);
awmCreateCSS(0,1,0,n,'#FFFFFF',n,n,n,'outset',2,'#C0C0C0',0,0);
awmCreateCSS(1,2,1,'#000000','#FFFFFF',n,'14px sans-serif',n,'none',1,n,0,1);
awmCreateCSS(0,2,1,'#FFFFFF','#AFAFAF',n,'14px sans-serif',n,'none',1,n,0,1);
awmCreateCSS(0,2,1,'#FFFFFF','#3F3F3F',n,'14px sans-serif',n,'none',1,n,0,1);
awmCreateCSS(1,2,1,'#FFFFFF','#000000',n,'14px sans-serif',n,'none',2,n,0,4);
awmCreateCSS(0,1,0,n,'#000000',n,n,n,'outset',2,'#C0C0C0',0,0);
awmCreateCSS(1,2,1,'#000000','#FFFFFF',n,'14px sans-serif',n,'none',1,n,2,1);
awmCreateCSS(0,2,1,'#FFFFFF','#AFAFAF',n,'14px sans-serif',n,'none',1,n,2,1);
awmCreateCSS(0,2,1,'#FFFFFF','#3F3F3F',n,'14px sans-serif',n,'none',1,n,2,1);
awmCreateCSS(1,2,0,'#FFFFFF','#000000',n,'14px sans-serif',n,'none',2,n,0,4);
awmCreateCSS(1,2,2,'#000000','#FFFFFF',n,'14px sans-serif',n,'none',1,n,4,1);
awmCreateCSS(0,2,2,'#FFFFFF','#AFAFAF',n,'14px sans-serif',n,'none',1,n,4,1);
awmCreateCSS(0,2,2,'#FFFFFF','#3F3F3F',n,'14px sans-serif',n,'none',1,n,4,1);
awmCreateCSS(1,2,1,'#000000','#FFFFFF',n,'14px sans-serif',n,'none',1,n,4,1);
awmCreateCSS(0,2,1,'#FFFFFF','#AFAFAF',n,'14px sans-serif',n,'none',1,n,4,1);
awmCreateCSS(0,2,1,'#FFFFFF','#3F3F3F',n,'14px sans-serif',n,'none',1,n,4,1);
var s0=awmCreateMenu(0,0,0,0,1,0,1,0,0,30,30,1,1,1,0,"&nbsp Horizontal menu &nbsp","",n,1,1,0,1,n,n,100);
it=s0.addItem(2,3,4,"Infinite<br>&nbsp submenus &nbsp",n,n,"","",n,n,n,"http://www.likno.com/?source=app","new");
var s1=it.addSubmenu(0,0,-4,2,0,0,0,6,5,"&nbsp Submenu1 &nbsp","",n,1,1,1,0,n,n,100);
it=s1.addItemWithImages(2,3,4,"&nbsp;&nbsp;Item1&nbsp;&nbsp;",n,n,"",n,n,n,0,0,0,0,1,1,"",n,n,n,n,n);
var s2=it.addSubmenu(0,0,-4,2,0,0,0,6,5,"&nbsp Submenu2 &nbsp","",n,1,1,1,0,n,n,100);
it=s2.addItemWithImages(2,3,4,"&nbsp;&nbsp;Item2&nbsp;&nbsp;",n,n,"",n,n,n,0,0,0,0,1,1,"",n,n,n,n,n);
var s3=it.addSubmenu(0,0,-4,2,0,0,0,6,5,"&nbsp Submenu3 &nbsp","",n,1,1,1,0,n,n,100);
it=s3.addItemWithImages(2,3,4,"&nbsp;&nbsp;Item3&nbsp;&nbsp;",n,n,"",n,n,n,0,0,0,0,1,1,"",n,n,n,n,n);
var s4=it.addSubmenu(0,0,-4,2,0,0,0,6,5,"&nbsp Submenu4 &nbsp","",n,1,1,1,0,n,n,100);
it=s4.addItemWithImages(2,3,4,"&nbsp;&nbsp;Item4&nbsp;&nbsp;",n,n,"",n,n,n,0,0,0,0,1,1,"",n,n,n,n,n);
var s5=it.addSubmenu(0,0,-4,2,0,0,0,6,5,"&nbsp Unlimited submenus...","",n,1,1,1,0,n,n,100);
it=s5.addItem(2,3,4,"&nbsp;&nbsp;...and i could still go on!&nbsp;&nbsp;",n,n,"","",n,n,n,n,n);
it=s0.addItem(2,3,4,"Vertical<br>&nbsp submenus &nbsp",n,n,"","",n,n,n,"http://www.likno.com/?source=app","new");
var s1=it.addSubmenu(0,0,-4,2,0,0,0,6,5,"Vertical Submenu","",n,1,1,1,0,n,n,100);
it=s1.addItemWithImages(7,8,9,"&nbsp;with submenu title&nbsp;",n,n,"",n,n,n,0,0,0,0,1,0,"",n,n,n,n,n);
var s2=it.addSubmenu(0,0,-4,2,0,0,0,6,5,"Title","",n,1,1,1,0,n,n,100);
it=s2.addItem(7,8,9,"&nbsp;&nbsp;Item1&nbsp;&nbsp;",n,n,"","",n,n,n,n,n);
it=s2.addItem(7,8,9,"&nbsp;&nbsp;Item2&nbsp;&nbsp;",n,n,"","",n,n,n,n,n);
it=s2.addItem(7,8,9,"&nbsp;&nbsp;Item3&nbsp;&nbsp;",n,n,"","",n,n,n,n,n);
it=s1.addItemWithImages(7,8,9,"&nbsp;or without submenu title&nbsp;",n,n,"",n,n,n,0,0,0,0,1,0,"",n,n,n,n,n);
var s2=it.addSubmenu(0,0,-4,2,0,0,0,6,5,n,"",n,1,1,1,0,n,n,100);
it=s2.addItem(7,8,9,"&nbsp;&nbsp;Item4&nbsp;&nbsp;",n,n,"","",n,n,n,n,n);
it=s2.addItem(7,8,9,"&nbsp;&nbsp;Item5&nbsp;&nbsp;",n,n,"","",n,n,n,n,n);
it=s2.addItem(7,8,9,"&nbsp;&nbsp;Item6&nbsp;&nbsp;",n,n,"","",n,n,n,n,n);
it=s0.addItem(2,3,4,"Horizontal <br>&nbsp submenus &nbsp",n,n,"","",n,n,n,"http://www.likno.com/?source=app","new");
var s1=it.addSubmenu(1,0,-4,2,0,0,0,6,10,n,"",n,1,1,0,1,n,n,100);
it=s1.addItem(11,12,13,"&nbsp&nbsp Item1",n,n,"","",n,n,n,n,n);
it=s1.addItemWithImages(11,12,13,"&nbsp Item2",n,n,"",n,n,n,0,0,0,2,3,2,"",n,n,n,n,n);
var s2=it.addSubmenu(1,0,-4,2,0,0,0,6,5,"&nbsp Title here &nbsp","",n,1,1,0,1,n,n,100);
it=s2.addItem(14,15,16,"&nbsp;Item5&nbsp;",n,n,"","",n,n,n,n,n);
it=s2.addItem(14,15,16,"&nbsp;Item6&nbsp;",n,n,"","",n,n,n,n,n);
it=s1.addItem(11,12,13,"&nbsp&nbsp Item3",n,n,"","",n,n,n,n,n);
it=s1.addItem(11,12,13,"&nbsp&nbsp Item4",n,n,"","",n,n,n,n,n);
s0.pm.buildMenu();
}}
</script>




0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ngStyle with an input variable doesn't work 14 31
regx  exclude  pattern 6 29
Polygon I google maps 1 16
how would you interpret lines 3 31
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now