Board index » jbuilder » Referencing .class breaks javascript

Referencing .class breaks javascript


2006-07-06 01:01:15 AM
jbuilder24
This may be a little difficult to answer, but this is what I know. I've
created a very simple JBuilder web app project that basically contains a
.jsp, a .css, and a single java class. In the .jsp, I am running some
javascript that creates simulated tab pages using html buttons. If I try to
reference my java class in the javascript function, it seems like the
javascript function no longer runs. I don't have much experience with
non-weblogic web apps. Can you not reference a java class from javascript?
...Is the problem that the javascript is running on the client and the
.class lives on the server and there's no way the client code knows how to
get to the class?
My .jsp looks like this:
<html>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<link href="tabs.css" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="#ffffff" onload="tabLoad()">
<form method="post" action="myJSP.jsp">
Cust ID: <input name="" type="text" value="123456" size="8" />
<br />
<DIV ID="divTabButtons"></DIV>
<DIV ID="divTabFrame"></DIV>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
The javacript function looks like this:
function tabLoad() {
/* Referencing this class seems to make this function not run - I don't
see the alert() message
MyClass myClass = new MyClass();
String myString = myClass.getString();
/*
alert ("hello from tabLoad");
var HTML = "";
HTML += "<P ALIGN="+tabAlign+">";
for (var i = 0; i < tabs.length; i++) {
var tab = tabs[i].split("|");
HTML += "<INPUT TYPE='BUTTON' ID="+i+" CLASS='tabOff' VALUE="+tab[0]+"
onClick='tabOnClick("+i+")'> ";
}
divTabButtons.innerHTML = HTML;
for (var i = 0; i < tabs.length; i++) {
var tab = tabs[i].split("|");
if (tab[2] == "*") {
tabOnClick(i);
break;
}
}
}
 
 

Re:Referencing .class breaks javascript

Steve Kincer wrote:
Quote
This may be a little difficult to answer, but this is what I know. I've
created a very simple JBuilder web app project that basically contains a
.jsp, a .css, and a single java class. In the .jsp, I am running some
javascript that creates simulated tab pages using html buttons. If I try to
reference my java class in the javascript function, it seems like the
javascript function no longer runs. I don't have much experience with
non-weblogic web apps. Can you not reference a java class from javascript?
You cannot reference a java class from javascript. Java != Javascript.
These are two completely different languages.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:Referencing .class breaks javascript

Steve Kincer wrote:
teve Kincer wrote:
Quote
This may be a little difficult to answer, but this is what I know.
I've created a very simple JBuilder web app project that basically
contains a .jsp, a .css, and a single java class. In the .jsp, I am
running some javascript that creates simulated tab pages using html
buttons. If I try to reference my java class in the javascript
function, it seems like the javascript function no longer runs. I don't
have much experience with non-weblogic web apps. Can you not reference
a java class from javascript? ...Is the problem that the javascript is
running on the client and the .class lives on the server and there's no
way the client code knows how to get to the class?
Quote

You cannot call or create Java classes in a Java Script function. You
will need to instantiate the Java class within a scriptlet or
declaration. If you are getting a Java String from the java class, you
can assign it to a JavaScript variable.
Example:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<jsp:useBean id="hello" scope="request"
class="net.clc.hello.HelloWorldClass"/>
<jsp:setProperty name="hello" property="*" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<%
//Java Scriplet to get info from HelloWorldClass
String sHello=<jsp.getProperty id="hello" property="sayHello"/>
%>
<script language="JavaScript">
//Show a Alert button with Java Class, HelloWorldClass
function sayHello(){
var h="<%=sHello%>";
alert(h);
//Set the value with JavaScript
}
</script>
</head>
<body>
<h1>Hello World with Java and JavaScript</h1>
<a href="javascript:void()" onclick="javascript:sayHello();">Click
here for hello</a>
</body>
</html>
And here is the simple HelloWorldClass:
package net.clc.hello;
/**
*
* @author Compaq_Owner
*/
public class HelloWorldClass {
private String sayHello="Hello World from a Java Class";
/** Creates a new instance of HelloWorldClass */
public HelloWorldClass() {
}
public String getSayHello() {
return sayHello;
}
public void setSayHello(String sayHello) {
this.sayHello = sayHello;
}
}
 

{smallsort}