gigaZhang / struts2-jquery

Automatically exported from code.google.com/p/struts2-jquery
0 stars 0 forks source link

Tag <sj:a /> offers href="javascript:void(0)" #980

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello everyone,

I have tried to run a simple example into my Struts2 Web Application. It 
consists of inserting the first example in the "struts2-jquery-plugin" Project 
Home page:

    <div id="div1">Div 1</div>
    <s:url id="ajaxTest" value="/AjaxTest.action"/>

    <sj:a id="link1" href="%{ajaxTest}" targets="div1">
      Update Content
    </sj:a>

My web app is run inside JBOSS AS 7.1.1.

What steps will reproduce the problem?
1. Insert in the project the dependency to struts2-jquery-plugin (version 
3.5.1).
2. Insert <sj:head/> inside the <head /> section of the page. Insert the code 
above described in one of the pages.
3. Define the action in struts.xml (not using Convention plugin) as:

<action name="AjaxTest"                 class="com.myweb.action.MyAction"
            method="strutsJqueryTest">
            <result type="stream">
                <param name="contentType">text/html</param>
                <param name="inputName">inputStream</param>
            </result>                           
        </action>
4. Define the method "strutsJqueryTest":

public String strutsJqueryTest(){

        try{        

            String str = "STRUTS2-JQUERY-PLUGIN-OK";

            inputStream = new ByteArrayInputStream(
                    str.getBytes("UTF-8"));         

        }catch(Exception e){            
            try {
                inputStream = new ByteArrayInputStream("ERROR".getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }       
        }

        return SUCCESS;
    }

What is the expected output? What do you see instead?

"Div 1" string should be replaced by the String defined inside the action 
method ("STRUTS2-JQUERY-PLUGIN-OK"). 

However, I just see "javascript:void(0)". No Ajax action is performed :(

Which struts2 version? 2.3.14

Which struts2-jquery plugin version? 3.5.1

Thanks in advance

Please provide any additional information below.

Original issue reported on code.google.com by aloplo...@gmail.com on 20 May 2013 at 7:41

GoogleCodeExporter commented 9 years ago
OK, I was just this line in my <head> section:

<script type="text/javascript" src="jquery/jquery.min.js"></script>

which referenced jQuery-1.9.1.min. I read in another page that the plugin kept 
references to jQuery and jQueryUI. Currently, for 3.5.1 I checked that
jQuery was 1.8.3 and jQueryUI was 1.9.2.

I´m afraid I will have to use noConflict in some pages to support the plugin:
http://api.jquery.com/jQuery.noConflict/

Any other easier way to solve this problem?

Original comment by aloplo...@gmail.com on 20 May 2013 at 9:29

GoogleCodeExporter commented 9 years ago
You can simply overwrite the head.ftl template.

http://struts.apache.org/release/2.3.x/docs/template-loading.html

Original comment by johgep on 29 May 2013 at 4:58

GoogleCodeExporter commented 9 years ago
OK, that did the trick ;) Thank you very much.

This is what I did:

1 - Copy /template/jquery/head.ftl to the same folder in my classpath of the 
WAR file.

2 - Change:

<#if !jQueryVersion?? >
  <#assign jQueryVersion="X.Y.Z">   
</#if>

Where X.Y.Z is the desired version.

Insert:

<#-- <script type="text/javascript" 
src="${javaScriptBasePath}js/base/${jqueryFile}"></script> -->
<script type="text/javascript" src="jquery/${jqueryFile}"></script>

3 - Then, place the desired JS inside the src folder. In my case, the jquery 
folder of the classpath -> myProject.war/jquery/jquery-1.9.1.min.js

4 - Check with FireBug which version I was currently using: jQuery().jquery --> 
1.9.1

Is it possible to apply this patch also to jQuery UI or does it require more 
changes than a simple directory change?

Thanks again.

Original comment by aloplo...@gmail.com on 29 May 2013 at 8:32

GoogleCodeExporter commented 9 years ago
Ouch, Firebug detected that $.browser is not defined. 
I don´t know if it is really a big problem :S

http://stackoverflow.com/questions/5889279/browser-not-defined

(Please note that since the time of posting, this property has been removed in 
jQuery 1.9.)

Original comment by aloplo...@gmail.com on 29 May 2013 at 9:35

GoogleCodeExporter commented 9 years ago
-> Moved to struts2-jquery plugin version 3.6.0 with newer jQuery and jQueryUI 
libraries.

Original comment by aloplo...@gmail.com on 14 Jun 2013 at 10:14