File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing JSTL or EL as parameter in javaScript

 
Darren Alexandria
Ranch Hand
Posts: 185
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day!

Is it possible to pass JSTL or EL as parameter in javaScript?

Here's a snippet:


but this returned an undefined value.

Thanks!
 
Christophe Porteneuve
Author
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Darren,




but this returned an undefined value.


This looks perfectly valid, since your JS call here is apparently in the JSP. I don't think your problem lies in the script (although I assume you have a onclick handler, not a onKlick one�), but that you do not have a strMap variable handy in this context (or that this variable's toString method doesn't match your purpose).

You should double-check the presence and nature of this variable in your active scopes.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that this is not "passing" any data in the normal sense. The data will be inserted into the HTML/JavaScript page before being sent to the client.

As such, you can do a View Source on the page to see if the substitution happened as you expected.
 
Darren Alexandria
Ranch Hand
Posts: 185
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

Thanks for your replies!
Have already solved it!

It should be like this:



God bless you all!

[ February 12, 2008: Message edited by: Darren Alexandria ]
[ February 12, 2008: Message edited by: Darren Alexandria ]
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the only difference was putting single quotes instead of double quotes? Weird! I thought that didn't make a lot of difference with javascript (even though I like to stick to single quotes with javascript for no apparent reason). I still don't get the onKlick handler you are using. Is it a custom handler or what?
 
Christophe Porteneuve
Author
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the only difference was putting single quotes instead of double quotes? Weird! I thought that didn't make a lot of difference with javascript


It's not a JS issue, it's a HTML issue. The inline JS is an attribute value, and the attribute is delimited by double quotes, so putting double quotes in there breaks the attribute value (I should have seen it!).

The event handler's inline JS goes something like "insertText(", which obviously breaks.

Yet another reason why you should do away with inline JS and go unobtrusive�
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's really funny how sometimes you miss something that's really basic and elementary :roll: . Sorry for the double post earlier, but when I get those 503 and network error pages, I resubmit my post. I'll try to delete one of the two posts.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Christophe Porteneuve:
Yet another reason why you should do away with inline JS and go unobtrusive�

Indeed. Unobtrusive JavaScript is a topic we touched upon a few weeks back, and it bears re-emphasizing.

In the same way that CSS allowed us to segregate stylistic information from the document markup, unobtrusive JavaScript separates the behavior from the markup. This gives us all the "separation of concern" benefits, and avoiding aggravating syntax boofs like our OP stumbled upon.

So rather than declaring the onclick handler inline with the elements, it should be declared in the window onload handler or the document-ready handler.

In raw JavaScript:

Using the star of the week, Prototype:

And in jQuery:

Using either of Prototype or jQuery is highly recommended as both do a pretty good job of insulating you from the bumps of browser differences.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alaa Nassef:
I still don't get the onKlick handler you are using. Is it a custom handler or what?

The forum blocks certain words from being posted as a security concern. onclick and eval are two examples.

Posters frequently misspell these purposefully to get around the filter.

Of course, with a little HTML magic, you can easily post these: onclick onclick onclick onclick onclick onclick!

By substituting the corresponding HTML entity for any one of the characters, the filtering is avoided. For example, to enter onclick, you would type:
onclick
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, thanks Bear. Didn't know that.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic