This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Java to javascript and back again...please help:) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java to javascript and back again...please help:)" Watch "Java to javascript and back again...please help:)" New topic

Java to javascript and back again...please help:)

Kevin Hamrick
Ranch Hand

Joined: Aug 30, 2004
Posts: 37
What I am trying to do: A user hits the JSP on the web, the page hits an Oracle database and dynamically builds a sortable table.
Known problems: Besides the fact that it just isn�t working?
Passing the y value (a counter) to the JSP but even when I
Hard code in a value for y I get nothing.
Nothing displays.
I�ve extracted out most of the code and this should build a table within a &ITdiv> on another page but even when ran as a stand alone
I get errors. When I put it into the &ITdiv> All I see in the window where a table should be is my source code.
I�ve posted this in the JSP section and in Java section because I do not know where it should go.
As always, Thanks for the insights. I need some help as I have been struggling all week-end with this.

Side Note: all �less then� signs had to replaced with �&it�
And �onclick� had to replace with �onKlick� in order to post.

&IT%@ page import="java.sql.*" %>
&IT%@ page import="java.text.SimpleDateFormat" %>
&IT%@ include file="connectDB.jsp" %>
&ITSCRIPT FOR=window EVENT=onload LANGUAGE="javascript">

&IT% System.out.println("--------------------starting page--------------------");%>
&ITtable id="tblMISSION" width="100%">
&ITtr bgcolor="lightyellow" style="font-size:10;font-weight:bold;font-family:arial" style="position:relative; top:expression(this.offsetParent.scrollTop -2);left: -1">
&ITth>&ITa href="#" title="Number" onklick="return sortTable(this)">#&IT/a>&IT/th>
&ITth>&ITa href="#" title="NAME" onklick="return sortTable(this)">NAME&IT/a>&IT/th>
&ITth>&ITa href="#" title="CITY" onklick="return sortTable(this)">CITY&IT/a>&IT/th>
&ITth>&ITa href="#" title="GENDER" onklick="return sortTable(this)">GENDER&IT/a>&IT/th>

&ITtd title="Number">#&IT/td>
&ITtd title="NAME">NAME&IT/td>
&ITtd title="CITY" >CITY&IT/td>
&ITtd title="GENDER" >GENDER&IT/td>

SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yy");


ResultSet rs = statement.executeQuery(sql);
String num="";
String name="";
String city="";
String gender="";

int counter=0;
System.out.println("--------------------calling while("")--------------------");
while (
//System.out.println("--------------------Hitting database--------------------");
if(num == null){num = "";}
if (name==null){name="";}
if(city == null){city = "";}
if (gender==null){gender="";}

// add a step to convert from java to jsScript and put into an array
&IT!-- Make a call to js to put all the data in a js array of data objects to be sorted. -->
SDBObject(num,name,city,gender, &IT% counter %> ;


&IT!�I was just hard coding a table in here originally

&ITtbody id="sortData">&IT/tbody>
&ITSCRIPT LANGUAGE="JavaScript">drawTable("sortDate");&IT/SCRIPT>

function drawTable(tbody) {
var tr, td;
tbody = document.getElementByID(tbody);
for(var k = 0; k &IT jsData.length; k++) {
tr = tbody.insertRow(tbody.row.length);
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].Num;
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].NUM;
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].NAME;
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].CITY;
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].GENDER;
td = tr.insertCell(tr.cells.length);

function sortTable(link) {
case "NUM":
case "MISSION":
return false;
}//end sortTable(link) function
function SDBObjects(name, city,gender, i){
jsData[i] = {Num: i,NAME: name, CITY: city, GENDER: gender };
function sortByMission(a,b){
a = a.location.toLowerCase();
b = b.location.toLowerCase();
return((a&ITb) ? -1 (a>b) ? 1:0));
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Did you try to use Code Tags?
[ January 25, 2005: Message edited by: Carol Enderlin ]
Kevin Hamrick
Ranch Hand

Joined: Aug 30, 2004
Posts: 37
Didn't know about the code is the example again. I still needed to replace onclick with onKlick..please help
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
You've got some extra script tags. What should be inside script tags? Stuff like functions. Not HTML, not scriptlets. Do you have end script tags for each start script tag? I guess I looked really quickly, but they seem to be nested and I didn't see very many end tags. What are you trying to do with the onload? I would expect to see javascript such as function calls inside the onload script tag.

Also, have you thought about using javabeans, jstl, etc. to get the java out of your jsp?

I agree. Here's the link:
subject: Java to javascript and back again...please help:)
It's not a secret anymore!