Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javacript variables within EL syntax methods invocation

 
Luciano Daher
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

I recently got here and I'm already a big fan of yours, not to mention the fact that I bought almost the entire Head First collection.

I've seen some posts here bringing up the opposite, as how to pass a EL param (or whatever) value to a Javascript function.

But the goal here is to do the inversion, that is, pass via Javascript set variable a value to be processed within a Java method set in TLD file.

Did I make myself clear? If so, Is that possible?

Note: I was wondering to accomplish that using Javascript window.location instruction adding a "name=value" par at the end of a URL to be caught within EL param, but this approach hasn't sound pretty good, isn't it?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64685
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luciano Daher wrote:Did I make myself clear? If so, Is that possible?

It is not. JSP executes on the server to create the HTML page to send to the client, where the JavaScript is evaluated and executed. They not only don't run on the same machine, they don't even exist at the same time.

See this article to understand how JSP works and why what you are trying to do is not possible.

Note: I was wondering to accomplish that using Javascript window.location instruction adding a "name=value" par at the end of a URL to be caught within EL param, but this approach hasn't sound pretty good, isn't it?

Not sure what you are actually trying to do. Could you try to explain it a bit more clearly?
 
Luciano Daher
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply...

Note: I understand when you said about the .JSP being turned into .JAVA, compiled and then it's returned to the client as a .HTML page when the JSP is requested for the first time, which that makes it impossible to achieve what I want, but anyway...

Just to explain what I was intended to do.

It sounds a little bit silly what I'm trying to do but, lets suppose you have a Footer.jsp to be included via standard action within a Main.jsp page and, using standard action, I'd be able to call Java regular methods within an EL syntax (e.g. ${someMethod(String)}) via TLD configuration file.

To turn this example more interesting, at the Java method signature, I added a String argument to be returned, lets suppose, the current time as a String. To satisfy this particular String argument, I would like to pass to it a Javascript var called "time" which is updated via "window.setInterval()" each 1 second to correspond Clock's second.

I know, it's a stupid example, but I'd like to know whether this is possible to achieve or not.
 
Paul Clapham
Sheriff
Pie
Posts: 20946
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your example, but the bottom line is that you can certainly generate Javascript code from your JSPs. You just can't execute them while the JSP is running.

So for example you could generate Javascript code which would be executed as soon as your generated page was loaded into the browser. That may or may not be relevant to your example, which as I said didn't make any sense to me.
 
Luciano Daher
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul as well!

It's now very clear for me. Just to make all what I've said understandable (if it's possible) I was expecting the Container not just transform the JSP into Java code and then compile it, as to interpret the Javascript content within the JSP Code, in special the resultant variable from the function inside "window.setInterval(...)" procedure, and a matter of fact, is the browser job.

This question would get into the list of the silliest questions ever, wouldn't it?

Thanks one more time for the refresh...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64685
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the article I linked to? It makes it clear that HTML and JavaScript in the JSP are not interpreted by the JSP engine at all -- it's just template text.
 
Luciano Daher
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I'd like to thank you both (you and Paul) specially you who was the first guy to remind me the "mechanism" involved on a JSP request. About the article, yes I did. By the way the Head First (Servlets & JSP) illustrates that concept very well.

Thank you one more time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic