Reputation: 643
In my webapp I am using struts2-jquery plugin.
Struts2 version - 2.3.7
struts.jquery.version - 3.5.0
For using jQuery with Struts I've used the following configurations -
In pom.xml
<dependency>
<groupId>com.jgeppert.struts2.jquery</groupId>
<artifactId>struts2-jquery-plugin</artifactId>
<version>${struts.jquery.version}</version>
</dependency>
In my JSP added the following tag:
<sj:head jqueryui="true"/>
And used an autocompleter
widget like this:
<s:url var="supUrl" namespace="/ajax" action="suppliers"/>
<sj:autocompleter
id="supplierMap"
name="echo"
label="Handle a Map"
href="%{supUrl}"
list="supplierMap"/>
I get the following JavaScript error:
Cannot call method 'bind' of undefined
jQuery.struts2_jquery_ui.bind(jQuery('#supplierMap_widget'),options_supplierMap_widget);
When I do View Page Source in the browser I see the following. Here the path for the JavaScript include is not the same as how it is packaged in struts2-jquery-plugin.jar.
<script type="text/javascript" src="/struts/js/base/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/struts/js/base/jquery.ui.core.min.js?s2j=3.5.0"></script>
<script type="text/javascript" src="/struts/js/plugins/jquery.subscribe.min.js"></script>
<script type="text/javascript" src="/struts/js/struts2/jquery.struts2.min.js?s2j=3.5.0"></script>
<script type="text/javascript">
$(function() {
jQuery.struts2_jquery.version="3.5.0";
jQuery.scriptPath = "/struts/";
jQuery.ajaxSettings.traditional = true;
jQuery.ajaxSetup ({
cache: false
});
jQuery.struts2_jquery.require("js/struts2/jquery.ui.struts2.min.js");
});
</script>
Upvotes: 3
Views: 6798
Reputation: 12261
My guess is that your problem has anything to do with any of the above answers.
As the error messages says, your problem is that jQuery.struts2_jquery_ui is undefined.
This is supplied as the code warns:
jQuery.struts2_jquery.require("js/struts2/jquery.ui.struts2.min.js");
This file is not in your tag. See the .ui. ???
What you have is:
"/struts/js/struts2/jquery.struts2.min.js?s2j=3.5.0"
Upvotes: 0
Reputation: 93
Maintain following version of jars in your lib. I think you won't face any problem
antlr-2.7.6.jar commons-beanutils-1.7.0.jar commons-collections-3.2.jar commons-digester.jar commons-fileupload-1.2.2.jar commons-io-2.4.jar
commons-lang-1.2.jar commons-logging-1.1.jar freemarker-2.3.16.jar javassist-3.7.ga.jar ognl-3.0.jar struts2-core-2.2.3.jar
xwork-core-2.2.1.jar struts2-jquery-plugin-3.1.1.jar
struts2
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter></i>
Upvotes: 0
Reputation: 1
try removing any namespace you might have added in struts.xml, adjust your urls accordingly. See if it works.
Upvotes: 0
Reputation: 2770
See, if you are using struts2jQuery plugin, you must have following filter-mapping of url pattern /* in web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Rest should work fine :)
Upvotes: 1