3

Have a <sj:tabbedppanel> on a page. After session timeout trying to click on another tab of tabbed panel should redirect the user to login poage. <sj:tabbed> panel not firing the onErrorTopics. Please see below and guide me on how to fix this issue. I am seeing in fire bug that the 403 error is thrown but I am unable to catch it in jsp. Need help with the same.

struts.xml

    <action name="secondPanel" class="com.xxx.secondPanelAction">
        <interceptor-ref name="sampleDefaultStack" />

        <result>/jsp/secondPanel.jsp</result> 
        <result name="login" type="httpheader">
            <param name="error">403</param>
            <param name="errorMessage">User session expired      </param>
        </result>
    </action>

jsp

<sj:tabbedpanel id="remotetabs" selectedTab="0" show="true"   hide="'fade'" collapsible="true" sortable="true" onErrorTopics="loadError">
    <sj:tab id="tab2" href="%{createUrl}" key="label.create" onErrorTopics="loadError"/>
    <sj:tab id="tab1" href="%{updateUrl}" key="label.update" onErrorTopics="loadError"/>
</sj:tabbedpanel>

<script type="text/javascript" >
    $(document).ready(function() {  
      $.subscribe('loadError', function(event, data) { alert('in error');
      var status = event.originalEvent.status;

      if(status == 403 ) {
          window.location.href = "/Sample/login.action";
      }
    }); 
</script>
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
user3761541
  • 157
  • 2
  • 20

1 Answers1

2

I have made some test and here what I find.

Lets try a simple sj:div which is some how simpler. If you use the httpheader result with status:403 then you can use some thing like:

<sj:div href="/security/login.ib" onErrorTopics="loadError" targets="test">Test</sj:div>

  $.subscribe('loadError', function(event, data) {
      alert('some error happend');
      if(event.originalEvent.request.status){
          var status = event.originalEvent.request.status;
          alert(status);
      }
  });

Please not that you should use event.originalEvent.request.status

Back to sj:tab ....

The sj:tab is not working with onAlwaysTopics or onErrorTopics, seems to be a bug. However you can use onCompleteTopics or may be onChangeTopics.

<sj:tabbedpanel id="remotetabs" show="true"   hide="'fade'" collapsible="true" sortable="true" onCompleteTopics="loadError" >

But you can not use httpheader result. With status:403, the loadError will not called at all.

So you can use onCompleteTopics in your jsp and return a json which will let you know what should be done.

Or you can use

$(document).ajaxError( function(e, xhr, settings, exception) {

   if (xhr.status == 403) {
      //Do what you want

   }

}

Please not that the above ajaxError will be called for every ajaxError, not only when you change the tabs. May be you using settings.url can help.

Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173
  • See also [Differentiate between success data and error message to use in Struts 2](http://stackoverflow.com/a/20857989/573032). – Roman C Apr 01 '16 at 09:53