File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes A way around include's being position-sensative? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "A way around include Watch "A way around include New topic
Author

A way around include's being position-sensative?

Mike Spenser
Greenhorn

Joined: Jun 13, 2006
Posts: 21
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

Joined: Jan 10, 2002
Posts: 60994
    
  65

Move them to where you want them to be. What makes you think they need to be in the head?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Spenser
Greenhorn

Joined: Jun 13, 2006
Posts: 21
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

Joined: Jun 13, 2006
Posts: 21
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

Joined: Jan 10, 2002
Posts: 60994
    
  65

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

Joined: Dec 11, 2004
Posts: 13410

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


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mike Spenser
Greenhorn

Joined: Jun 13, 2006
Posts: 21
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

Joined: Jan 10, 2002
Posts: 60994
    
  65

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

Joined: Jan 10, 2002
Posts: 60994
    
  65

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

Joined: Jun 13, 2006
Posts: 21
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 10, 2002
Posts: 60994
    
  65

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 ]
 
jQuery in Action, 2nd edition
 
subject: A way around include's being position-sensative?