Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2216
  • Last Modified:

JSP Document (JSPX) Page does not run JQuery

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
zenserve
Asked:
zenserve
  • 5
  • 4
1 Solution
 
mrcoffee365Commented:
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
 
zenserveAuthor Commented:
You can download an example of this project from here: http://files.me.com/zenserve/78xjf4

0
 
mrcoffee365Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
zenserveAuthor Commented:
How is it that exactly the same JS code can be used by the JSP file without JavaScript errors?
0
 
mrcoffee365Commented:
XML being run through XSLT applies different parsers.  Do you see the errors in the Error Console?  Are you able to fix them?
0
 
zenserveAuthor Commented:
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
 
mrcoffee365Commented:
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
 
mrcoffee365Commented:
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
 
zenserveAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now