Struts 2 jquery plugin javascript error

2.9k views Asked by At

I have a Struts 2 application that use Tiles 3 and Struts 2 Jquery Plugin.

In the pom.xml:

<dependency>
  <groupId>com.jgeppert.struts2.jquery</groupId>
  <artifactId>struts2-jquery-plugin</artifactId>
  <version>3.7.1</version>
</dependency>

head.jsp:

<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sb" uri="/struts-bootstrap-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>

<s:head />

<!-- struts jquery head -->
<sj:head />

<!-- struts bootstrap head -->
<sb:head />

<!-- main stylesheet -->
<link href="static/css/main.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

The javascript console of the browser displays the following error: Uncaught TypeError: Cannot set property 'version' of undefined

The tag <sj:head /> print the following lines:

<script type="text/javascript" src="/MyApp/struts/js/base/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/MyApp/struts/js/base/jquery.ui.core.min.js?s2j=3.7.1"></script>
<script type="text/javascript" src="/MyApp/struts/js/plugins/jquery.subscribe.min.js?s2j=3.7.1"></script>

<script type="text/javascript" src="/MyApp/struts/js/struts2/jquery.struts2.min.js?s2j=3.7.1"></script>

<script type="text/javascript">
    $(function () {
        jQuery.struts2_jquery.version = "3.7.1";
        jQuery.scriptPath = "/MyApp/struts/";
        jQuery.struts2_jquery.gridLocal = "en";
        jQuery.struts2_jquery.timeLocal = "en";
        jQuery.ajaxSettings.traditional = true;

        jQuery.ajaxSetup({
            cache: false
        });

        jQuery.struts2_jquery.require("js/struts2/jquery.ui.struts2.min.js?s2j=3.7.1");

    });
</script>

The line that generate the undefined error is:

jQuery.struts2_jquery.version = "3.7.1";

After some javascript debug it seems that the function $.subscribeHandler is not defined.

1

There are 1 answers

0
danielevigi On BEST ANSWER

The problem was caused by a second inclusion of jquery in the footer