Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JSP Document (JSPX) Page does not run JQuery

Posted on 2009-07-10
9
Medium Priority
?
2,190 Views
Last Modified: 2013-12-02
I have a web page, served by Tomcat, that's written using JSPX. The page contains a number of <div>s, each of which are hidden when it first loads. When the user clicks any of a number of different hyperlinks in the page, a JQuery function is executed to create a lightbox effect with the corresponding hidden <div> (essentially, each div can be displayed as a popup window).

However, when the page loads the <div>s are all visible, and nothing works. I'm getting a number of JQuery errors indicating that the browser had found problems within the main JQuery library code itself ("this._hide is undefined", "div.style is undefined").

What's extremely strange about this is that the JSP version of the page (that is, the non-XML version) works perfectly without any errors.

My initial assumption is that the DOM for a JSPX page is built in a different manner than one for a JSP page. Alternatively, perhaps this is something to do with the way JQuery works - I've noticed that if I reorder the various JQuery UI library file <script> entries within the page, the error changes, indicating that the function is executing before the rest of the libraries are loaded or the page is completely built.

But honestly, I've no idea. Any takers?

I will post code if necessary, but if someone can get a JSPX page that does something similar using JQuery working on Tomcat 6, that would be a start.

Thanks in advance!
0
Comment
Question by:zenserve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 24836593
You definitely should post code if you're still working on it.    The issue is probably that you're not creating the xml and xslt files correctly, rather than a JSP problem.  I suppose it could be JQuery, but again -- that doesn't change, so it's more likely an issue with xml and xslt.
0
 

Author Comment

by:zenserve
ID: 24838238
You can download an example of this project from here: http://files.me.com/zenserve/78xjf4

0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 24838646
The output from your .jspx page has a few Javascript errors.  In Firefox, look at the Error Console when you load the page.

If you fix those errors, then the divs might be hidden the way you want them to be.
0
Vim Reference Guide

Vim is a powerful text editor favored by many sysadmins and developers - here are some commands that you'll want to keep in your back pocket!

 

Author Comment

by:zenserve
ID: 24838745
How is it that exactly the same JS code can be used by the JSP file without JavaScript errors?
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 24838883
XML being run through XSLT applies different parsers.  Do you see the errors in the Error Console?  Are you able to fix them?
0
 

Author Comment

by:zenserve
ID: 24848769
I see the errors - these are the ones I mentioned in my original post. The JQuery code is bug free, and works perfectly in the "this_works.jsp" file I sent.

I just noticed that if I rename the "this_does_not.jspx" file to "this_does_not.html" the JQuery works. Of course, if I do this now it does not compile as a JSP...
0
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 1500 total points
ID: 24849594
Yes, the whole point is that if the file is .jspx, then a different set of parsers come into play.  Your code also runs as .jsp, for the same reason - if it's JSP, then the XML parser is not involved.

If you want the .jspx file to run as .jspx, then you have to work your way through all of the XML parsing issues.  It's a pain -- no ampersands, no less than or greater than symbols, etc.  That's probably what is causing the errors from the javascript which is executing -- it creates HTML, and those symbols are a central part of HTML.

This discussion gives some examples of the kinds of changes you have to make to make a .jspx document parse:
http://java.dzone.com/news/death-xslt-web-frameworks

This jspx documentation shows you what the .jspx page is translated into:
http://jspx.sourceforge.net/

Here's is Sun's tutorial on jspx (which you might have seen, but just in case):
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPX3.html

0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 24849615
I assume that you got those javascript libraries from somewhere else, so it's going to be a lot of work to make them work correctly for you in the .jspx page (that is, make them parse correctly for an XML parser).  It might be that you can't use those javascript libraries in a .jspx page, because it's too much work to convert them.
0
 

Author Comment

by:zenserve
ID: 24850246
I took on board what you said and then had a think about what might be happening when the XML is parsed. This led to a eureka moment.

The issue was that the parser was turning empty elements such as <div></div> into <div/>. Adding a non-breaking white space (where permitted) fixes the problem; the DOM builds correctly and the JQuery executes without errors.

Many thanks!
0

Featured Post

ATEN's HDBaseT Presentation at InfoComm 2017

Hear ATEN Product Manager YT Liang review HDBaseT technology, highlighting ATEN’s latest solutions as they relate to real-world applications during her presentation at the HDBaseT booth at InfoComm 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question