Here's what I came up with:

In my jsp:
<%@ page import="myclasses.Finals" %>
<script type="text/javascript" language="javascript">
  <%@ include file="myscript.js" %>
</script>

In myscript.js:
function myFunction()
{
  if (formAction == "<%= Finals.RESET %>")
  {
    // reset the page, etc.
  }
}

The only problem that I can see is that this sort of defeats one of the 
purposes for having functions in an external file: hiding your 
javascript code. I'm not sure how big of an issue that is because you 
can find the .js file in cache anyway.

Thanks for all of the help!

Jason

----- Original Message -----
From: Tan Chao Ying <[EMAIL PROTECTED]>
Date: Tuesday, May 14, 2002 0:57 am
Subject: [jdjlist] 
=C4jdjlist=DC_RE=3A_Static_class_variables_in_Javascript

> Hello Jason,
> JavaScript is executed at the clientside and java at the 
> serverside. During
> the html creation you have the fully access of javacode, so what 
> you can do
> is, should be like this :
> 
>    if (formAction == "<%=Finals.REFRESH%>")
>    .
>    .
>    .
>    else if (formAction == "<%=Finals.RESET%>")
>    .
> 
> Through the JSP-Compiler the HTML-Code, that the browser received 
> will be
> like what you want to acceive :
> 
>    if (formAction == "refresh")
>    .
>    .
>    .
>    else if (formAction == "reset")
>    .
> 
> regards
> Chao Ying
> 
> 
> -----Urspr�ngliche Nachricht-----
> Von: Jason Kilgrow [mailto:[EMAIL PROTECTED]]
> Gesendet: Monday, May 13, 2002 8:00 PM
> An: JDJList
> Betreff: �jdjlist� RE: Static class variables in Javascript
> 
> 
> Let me get a bit more specific.
> I have a class called Finals.class that has the following:
> 
> public static final String REFRESH = "refresh";
> public static final String RESET = "reset";
> 
> etc...
> 
> In my javascript file (let's call it my.js) I have a number of
> functions. One of these functions is called
> "handleSubmit(formAction)" where formAction is a string.
> 
> function void handleSubmit(formAction)
> {
>    if (formAction == "refresh")
>    {
>        // do the refresh stuff
>    }
>    else if (formAction == "reset")
>    {
>        // do the reset stuff
>    }
> }
> 
> What I want to do is this:
>    .
>    .
>    .
>    if (formAction == Finals.REFRESH)
>    .
>    .
>    .
>    else if (formAction == Finals.RESET)
>    .
>    .
>    .
> 
> Any suggestions? In the meantime, I'll take a look at Liveconnect.
> I've heard of it but I'm skeptical that it'll do what I want.
> 
> --- "Cote, Robert" <[EMAIL PROTECTED]> wrote:
> > Not knowing your specific requirements, I do a fair bit of the
> > following in
> > my JSPs (intranet application):
> > 
> > <body onLoad="doSomething(<%objRef.getWhateverProperty()%>)">
> > 
> > Netscape defined LiveConnect (at least in js 1.3 spec) for
> > communication
> > between js and java -- I haven't worked with it, and I'd bet
> > against
> > internet explorer support.
> > 
> > -----Original Message-----
> > From: Jason Kilgrow [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, May 13, 2002 11:50 AM
> > To: JDJList
> > Subject: [jdjlist] Static class variables in Javascript
> > 
> > 
> > Does anyone know if it's possible to access static final class
> > properties from Javascript? If it is possible, how is it done?
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > LAUNCH - Your Yahoo! Music Experience
> > http://launch.yahoo.com
> > 
> > To change your membership options, refer to:
> > http://www.sys-con.com/java/list.cfm
> > 
> > To change your membership options, refer to:
> > http://www.sys-con.com/java/list.cfm
> 
> 
> __________________________________________________
> Do You Yahoo!?
> LAUNCH - Your Yahoo! Music Experience
> http://launch.yahoo.com
> 
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm
> 
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm
>


To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to