Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A way around include's being position-sensative?

 
Mike Spenser
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anyway around <@include or jsp:include's position sensativity?

I want to change the content dynamically based on what a user clicks on the page and would like to encapsulate the new content in jspf files.

so basically there's a big javascript if/else block run when the user does something, contained up in the <head> area.

but @include and jsp:include just (basically) insert the .jspf code or response exactly where they are located. And I need their data down in the body.

Any ideas?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move them to where you want them to be. What makes you think they need to be in the head?
 
Mike Spenser
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because its all wrapped in a somewhat complicated javascript function that I'd prefer to keep in the head because I want to use the output from the jspf to be used for a

document.innerHTML modification of the DOM
 
Mike Spenser
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also doesn't the jsp code evaluate first?

so even if I have it all wrapped up in an if/else block won't the file use the include when its first loaded regardless of whether the if/else conditions have been met?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Spenser:
Also doesn't the jsp code evaluate first?


Yes, did you read the article that I pointed to in your previous post?


so even if I have it all wrapped up in an if/else block won't the file use the include when its first loaded regardless of whether the if/else conditions have been met?


Yes. So if your jspf's are including JavaScript template text, it shouldn't matter where you put them as the JavaScript will run on the browser at its appointed time.

It still sounds to me as if you are mixing server-side and client-side code in some odd way. Or perhaps you just need to explain what you are trying to do in a bit more detail.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also want to look at our FAQ entry on the difference between the include action and include directive.
http://faq.javaranch.com/view?IncludesActionDirective
 
Mike Spenser
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I've tried to strip out as much extraneous tags as possible. Please excuse how poorly formated this is. Also I had to put a space in the onclick command because the forum refused to accept it, even with all the code in code tags and all the HTML properly escaped.




does that make any more sense as to what I'm trying to do?

update::


Anyway to make this work?


[ June 15, 2006: Message edited by: Mike Spenser ]
[ June 15, 2006: Message edited by: Mike Spenser ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I suspected, you're trying to use a client-side if to control server-side code. No can do.

Did you read the article?

You can do what you want using Ajax to load a snippet from the server under JavaScript control.

Also, why are all your quotes escaped in the code?
[ June 15, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Spenser:

Anyway to make this work?



So you didn't read the article which explains this in great detail.
 
Mike Spenser
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes everything was properly escaped. I used a script to escape all characters, but for some reason the forum said there was something wrong with "onclick" which is odd, since there's nothing really to be escaped there.

I did read the article and have a much better understanding now. Thanks. That edited comment was because I was still logged in and someone else had an idea as to how to do it.

ok, I'll just stay away from include directives and jsp:include for what I want to do.

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Spenser:

ok, I'll just stay away from include directives and jsp:include for what I want to do.

You DO realize that it doesn't matter which you use if you are going to do the branching in on the client with Javascript, right?

The full text of both will need to be there if you want to toggle back and forth without making a new call to the server.

Viewing the HTML source from the browser is a good habit to get into until you have a firm grip on where JSP and Javascript get executed/interpreted.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Spenser:
yes everything was properly escaped.


So it's not that way in your code? (I hope).

You don't need to do that to post to the forum.

The forum code filters out certains words like onclick and cookie. To enter them, subsitute the HTML entity &#111; for the small 'o'.


I did read the article and have a much better understanding now. Thanks.


Cool. So you now understand why you can't "if" on the client to control server-side code.


ok, I'll just stay away from include directives and jsp:include for what I want to do.


There are ways to do what you want to do; just not that way.
[ June 15, 2006: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic