Re: ApplicationResources.properties and JavaScript

2008-08-07 Thread Wes Wannemacher
On Thu, 2008-08-07 at 17:43 -0700, Dave Newton wrote:
> --- On Thu, 8/7/08, nauke. <[EMAIL PROTECTED]> wrote:
> > No matter how I tried to pass those values in as
> > parameters, my JavaScript function kept treating 
> > it as literal text
> > 
> > Like:
> > 
> > <%=String aString = "Hi There!"%>

Periodically, I run into this problem and find out that I don't have
*.js files mapped to the JSP servlet in Tomcat. It may not be your
problem, but if you are running javascript that comes from a separate
file with a .js file extension, tags and scriptlets don't work unless
you have mapped them to the JSP servlet. 

I've had this problem when using tags in both JS and CSS files. It's
easy enough to fix, but it's a mistake I make with every project I start
from scratch and always takes me an hour or more to figure out :)

-Wes

PS - Dave, I caught myself this time, I almost sent this only to you
again!


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ApplicationResources.properties and JavaScript

2008-08-07 Thread Dave Newton
--- On Thu, 8/7/08, nauke. <[EMAIL PROTECTED]> wrote:
> No matter how I tried to pass those values in as
> parameters, my JavaScript function kept treating 
> it as literal text
> 
> Like:
> 
> <%=String aString = "Hi There!"%>

That's most likely not what you wanted, you mean:

<% String aString = "Hi There!"; %>

Hopefully that was typos.

> onclick="return myFunc('<%=aString%>');"

Do you have scriptlets enabled?

> myFunc('msg')

Er, if *that* doesn't work, then you've done something horribly wrong, because 
that's just calling a JavaScript function with a literal string.

Dave


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ApplicationResources.properties and JavaScript

2008-08-07 Thread nauke .
Hi Dave,

Thanks for replying.
Yeah I declared variables in my JSP file and tried to parse them through as
arguments to the JavaScript function like mentioned.
No matter how I tried to pass those values in as parameters, my JavaScript
function kept treating it as literal text hehe!

Like:

<%=String aString = "Hi There!"%>

onclick="return myFunc('<%=aString%>');"

myFunc would print out "<%=aString%>" rather than "Hi There!".

Also tried:

myFunc(<%=aString%>);

i.e. without the single quotes.

Also tried:

myFunc('msg')

etc etc.

Funny because I've done this in other JSPs.

Yes that underlying fact with client and server side resources.

Ah well ... Thanks again.
Nicole


On Fri, Aug 8, 2008 at 9:27 AM, Dave Newton <[EMAIL PROTECTED]> wrote:

> --- On Thu, 8/7/08, nauke wrote:
> > There must be a more elegant solution than this!
>
> Not really: you're trying to access server-side resources from the client
> side. If you're not going to run your JavaScript through the JSP processor
> your options are limited, for obvious reasons.
>
> One solution was already given to you: deal with server-side resources in
> the JSP, use them as arguments to JavaScript functions contained in an
> external JavaScript file, by using custom tags, scriptlets, etc. to set
> parameter values.
>
> You can also generate JavaScript on the server-side by means other than a
> JSP (FreeMarker, servlet, etc.), or generate JavaScript during the build
> process, or generate the JavaScript at application startup, or use something
> like DWR to access a Java object that loads resources at runtime, or... ad
> nauseum.
>
> The underlying issue won't go away; there's client-side resources, and
> there's server-side resources. That's one of the many unfortunate natures of
> web applications, AFAICT.
>
> Dave
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Re: ApplicationResources.properties and JavaScript

2008-08-07 Thread Dave Newton
--- On Thu, 8/7/08, nauke wrote:
> There must be a more elegant solution than this!

Not really: you're trying to access server-side resources from the client side. 
If you're not going to run your JavaScript through the JSP processor your 
options are limited, for obvious reasons.

One solution was already given to you: deal with server-side resources in the 
JSP, use them as arguments to JavaScript functions contained in an external 
JavaScript file, by using custom tags, scriptlets, etc. to set parameter values.

You can also generate JavaScript on the server-side by means other than a JSP 
(FreeMarker, servlet, etc.), or generate JavaScript during the build process, 
or generate the JavaScript at application startup, or use something like DWR to 
access a Java object that loads resources at runtime, or... ad nauseum.

The underlying issue won't go away; there's client-side resources, and there's 
server-side resources. That's one of the many unfortunate natures of web 
applications, AFAICT.

Dave


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ApplicationResources.properties and JavaScript

2008-08-07 Thread nauke .
Hi Owen,

Thanks for your reply.
I think I did try that.
The only solution I have found to work was to do this:

Application.properties:
my.message=Hi There!

myJSPFile.jsp:


myJSFile.js
var msg = document.myform.myMessage.value;
alert(msg);

The deadline is today so I'll have to do what works so far :(((

Thanks heaps to all for trying to help.
There must be a more elegant solution than this!

Cheers

On Fri, Aug 8, 2008 at 8:58 AM, Owen Berry <[EMAIL PROTECTED]> wrote:

> In your jsp code set a variable to be the value you want, as shown
> earlier in this thread by Balwinder, and then read that variable in
> your Javascript code. If you're using OO javascript, you can make it
> nice and tidy by passing the parameter in your "constructor", or set
> it in a method. Example:
>
> var obj = new FancyObject(' bundle="MESSAGE">');
> // -- or --
> obj.setSomeValue('');
>
> Make sense?
>
> On Thu, Aug 7, 2008 at 7:03 PM, nauke. <[EMAIL PROTECTED]> wrote:
> > Thanks for that.
> > I think that only works if the javascript is within the JSP file right?
> > My javascript functions are in it's on .js file ...
> >
> > On Thu, Aug 7, 2008 at 8:23 PM, Balwinder <[EMAIL PROTECTED]> wrote:
> >
> >> nauke. wrote:
> >>
> >>> Hi all,
> >>>
> >>> Is there a way to access values in ApplicationResources.properties in
> >>> Javascript functions?
> >>> I've found a way where I can just pass a value from the app resource
> file
> >>> as
> >>> a parameter, but discovered that I return alerts with different
> messages
> >>> based on some criteria.
> >>>
> >>> Any ideas?
> >>>
> >>> Thanks heaps
> >>>
> >>>
> >>>
> >> Try this
> >> 
> >> var someVar = '';
> >> 
> >>
> >>
> >> hope this will serve the purpose.
> >>
> >>
> >> -
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Re: ApplicationResources.properties and JavaScript

2008-08-07 Thread Owen Berry
In your jsp code set a variable to be the value you want, as shown
earlier in this thread by Balwinder, and then read that variable in
your Javascript code. If you're using OO javascript, you can make it
nice and tidy by passing the parameter in your "constructor", or set
it in a method. Example:

var obj = new FancyObject('');
// -- or --
obj.setSomeValue('');

Make sense?

On Thu, Aug 7, 2008 at 7:03 PM, nauke. <[EMAIL PROTECTED]> wrote:
> Thanks for that.
> I think that only works if the javascript is within the JSP file right?
> My javascript functions are in it's on .js file ...
>
> On Thu, Aug 7, 2008 at 8:23 PM, Balwinder <[EMAIL PROTECTED]> wrote:
>
>> nauke. wrote:
>>
>>> Hi all,
>>>
>>> Is there a way to access values in ApplicationResources.properties in
>>> Javascript functions?
>>> I've found a way where I can just pass a value from the app resource file
>>> as
>>> a parameter, but discovered that I return alerts with different messages
>>> based on some criteria.
>>>
>>> Any ideas?
>>>
>>> Thanks heaps
>>>
>>>
>>>
>> Try this
>> 
>> var someVar = '';
>> 
>>
>>
>> hope this will serve the purpose.
>>
>>
>> -
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ApplicationResources.properties and JavaScript

2008-08-07 Thread nauke .
Thanks for that.
I think that only works if the javascript is within the JSP file right?
My javascript functions are in it's on .js file ...

On Thu, Aug 7, 2008 at 8:23 PM, Balwinder <[EMAIL PROTECTED]> wrote:

> nauke. wrote:
>
>> Hi all,
>>
>> Is there a way to access values in ApplicationResources.properties in
>> Javascript functions?
>> I've found a way where I can just pass a value from the app resource file
>> as
>> a parameter, but discovered that I return alerts with different messages
>> based on some criteria.
>>
>> Any ideas?
>>
>> Thanks heaps
>>
>>
>>
> Try this
> 
> var someVar = '';
> 
>
>
> hope this will serve the purpose.
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Re: ApplicationResources.properties and JavaScript

2008-08-07 Thread Balwinder

nauke. wrote:

Hi all,

Is there a way to access values in ApplicationResources.properties in
Javascript functions?
I've found a way where I can just pass a value from the app resource file as
a parameter, but discovered that I return alerts with different messages
based on some criteria.

Any ideas?

Thanks heaps

  

Try this

var someVar = '';



hope this will serve the purpose.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



ApplicationResources.properties and JavaScript

2008-08-06 Thread nauke .
Hi all,

Is there a way to access values in ApplicationResources.properties in
Javascript functions?
I've found a way where I can just pass a value from the app resource file as
a parameter, but discovered that I return alerts with different messages
based on some criteria.

Any ideas?

Thanks heaps