gigaZhang / struts2-jquery

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

Jquery script is not working when the page is included in Struts2 tiles. But its functioning when I invoke the page directly #799

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
(This is for feature requests and bugs in Struts2 jQuery Plugin - for
getting help, please use the User Group.
http://groups.google.com/group/struts2-jquery )

What steps will reproduce the problem?
1. Code from my JSP.

File name: test.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<sj:head />

<s:url id="ajax" value="/exchangeRate.action">

    </s:url>
    <sj:div id="resultnormal" href="%{ajax}" indicator="indicator"
        onBeforeTopics="beforeDiv" onCompleteTopics="completeDiv"
        onErrorTopics="errorDiv"
        cssClass="result ui-widget-content ui-corner-all">
        Loading..
    </sj:div>   
    <br /> <strong>Div with invalid URL:</strong>
    <sj:div id="resulterror" href="/not_exist.html" indicator="indicator"
        onCompleteTopics="completeDiv" onErrorTopics="errorDiv"
        cssClass="result ui-widget-content ui-corner-all">
        Loading
    </sj:div>

2. Invoked test.jsp directly it worked fine.
3. I have included test.jsp in a tiles definition

<definition name="baseLayout" template="/pages/common/BaseLayout.jsp">
        <put-attribute name="title" value="" />     
        <put-attribute name="body" value="" />  
        <put-attribute name="header" value="/pages/common/test.jsp" />          
</definition>

in web.xml

<listener>
    <listener-class>
        org.apache.struts2.tiles.StrutsTilesListener
    </listener-class>
</listener>
    <context-param>
        <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
        <param-value>/WEB-INF/tiles.xml</param-value>
    </context-param>

4. Invoked by an action

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

a. In div id "resultnormal" the result displayed but there was not Alert. But 
Alert should come first and then the result.
b. in div id "resulterror" its still showing "loading" text. But Expecting 
"Error request Not Found completed with error.
Status: 404"

Which struts2 version?
2.3.1.2

Which struts2-jquery plugin version?
3.3.0

Please provide any additional information below.

I also tried putting <sj:head/> on the basicLayout.jsp but still javascript 
methods are not getting called when the page is part of a tiles definition. It 
perfectly works fine when the page is invoked directly.

Please advice what's wrong with my settings..

Original issue reported on code.google.com by tis...@gmail.com on 27 Mar 2012 at 1:56

GoogleCodeExporter commented 9 years ago
Sorry I have missed the script to copy..

<script type="text/javascript">
    $.subscribe('beforeDiv', function(event, data) {
        alert('Before request ');
    });
    $.subscribe('completeDiv', function(event, data) {
        if (event.originalEvent.status == "success") {
            $('#resultnormal').append(
                    '<br/><br/><strong>Completed request '
                            + event.originalEvent.request.statusText
                            + ' completed with ' + event.originalEvent.status
                            + '.</strong><br/>Status: '
                            + event.originalEvent.request.status);
        }
    });
    $.subscribe('errorDiv', function(event, data) {
        $('#resulterror').html(
                '<br/><br/><strong>Error request '
                        + event.originalEvent.request.statusText
                        + ' completed with ' + event.originalEvent.status
                        + '.</strong><br/>Status: '
                        + event.originalEvent.request.status);
    });

    $.subscribe('completediv2', function(event, data) {
        alert(event.originalEvent.status);
        setTimeout(function() {
            $.publish('reloaddiv2');
        }, 10000);

    });
</script>

Original comment by tis...@gmail.com on 27 Mar 2012 at 2:58

GoogleCodeExporter commented 9 years ago
Can you please prepare a simple tiles webapp and attach it here?

Original comment by johgep on 15 May 2012 at 3:01

GoogleCodeExporter commented 9 years ago
I have a tiles app which is running fine with s2j plugin.

Original comment by johgep on 8 Sep 2012 at 5:06

GoogleCodeExporter commented 9 years ago
johgep

I have the same problem:

The script:

        <script type="text/javascript">
            $.subscribe('onBeforeLoading', function(event,data) {
                $(".ui-dialog-titlebar").hide();
                $("#dialogCarregando").dialog('open');   
            }); 

            $.subscribe('onCompleteLoading', function(event,data) {
                $("#dialogCarregando").dialog('close');
            });             
        </script>

The dialog:

        <sj:dialog 
            id="dialogCarregando"           
           title=""        
           autoOpen="false"
           modal="true"
           resizable="false"
           closeOnEscape="false"           
        >
            <div>
                <br/>
                <br/>
            <center><img id="indicatorLoading" src="<s:url value="/images/indicator.gif" />" alt="Wait..." /> Wait a moment...</center>
            </div>
        </sj:dialog>

And the button:

        <s:url 
            id="url_valida_login" 
            action="validaLoginResponsavel" 
        />

        <sj:submit 
            value="Login" 
            href="%{url_valida_login}" 
            button="true" 
            targets="divConteudo"
            cssClass="btn btn-primary btn-lg"
            onBeforeTopics="onBeforeLoading"                                                                        
            onCompleteTopics="onCompleteLoading"                                                            
        />

When I use tiles, dialog is not close after execute completeTopics.

Any idea ?

Sérgio

Original comment by sergio...@gmail.com on 4 Mar 2015 at 1:07