When navigating from one tab to another, i.e, on clicking the submit button in a tab1 (which is jsp) the tab2 has to get loaded. My code is below.
<sj:tabbedpanel id="remotetabs" onCompleteTopics="tabcomplete"
onChangeTopics="tabchange">
<sj:tab id="tab1" href="test1.jsp" label="Tab One" />
<sj:tab id="tab2" href="test2.jsp" label="Tab Two" />
</sj:tabbedpanel><sj:submit></sj:submit>
The jsp I have used is
<s:url var="remoteurl1" action="ajax1" />
<s:url var="remoteurl2" action="ajax2" />
<sj:tabbedpanel id="tabpanel">
<sj:tab id="tab1" href="Test1.jsp" label="Tab One" />
<sj:tab id="tab2" href="Test2.jsp" label="Tab Two" />
</sj:tabbedpanel>
<sj:a href="#" onClickTopics="movetonextdiv" button="true">Next</sj:a>
and my script is
$.subscribe('movetonextdiv', function(event, data) {
var selected = $("#tabpanel").tabs('option', 'selected');
$("#tabpanel").tabs('option', 'selected', selected + 1);
});
I still face an issue like in the developer tools I am getting the error as Object doesn't support this property or method for the below line of code.
var selected = $("#tabpanel").tabs("option", "selected");
Here you go :
<sj:a href="#" onClickTopics="movetonextdiv" button="true">Next</sj:a>
<script>
$.subscribe('movetonextdiv', function(event, data) {
var selected = $("#tabpanel").tabs("option", "selected");
$("#tabpanel").tabs("option", "selected", selected + 1);
});
</script>
<sj:tabbedpanel id="tabpanel" >...</sj:tabbedpanel>
First, you should upgrade plugin to at least v3.6.1. Put $.subscribe
before the tag which sets topics to publish that you subscribed to. Make sure you have jQuery UI enabled.
<sj:head jqueryui="true" />
the script to sibscribe topics
<script type="text/javascript">
$(document).ready(function(){
$.subscribe('movetonextdiv', function(event, data) {
var el = $("#localtabs");
var size = el.find(">ul >li").size();
var active = el.tabs('option', 'active');
el.tabs('option', 'active', active + 1>=size?0:active + 1);
});
});
</script>
tabs with navigator button
<sj:a href="#" onClickTopics="movetonextdiv" button="true">Next</sj:a>
<br/>
<sj:tabbedpanel id="localtabs" cssClass="list">
<sj:tab id="tab1" target="jsp" label="JSP Code"/>
<sj:tab id="tab2" target="javascript" label="JavaScript"/>
<sj:tab id="tab3" target="java" label="Java"/>
<div id="jsp">
JSP
</div>
<div id="javascript">
JavaScript
</div>
<div id="java">
Java
</div>
</sj:tabbedpanel>
来源:https://stackoverflow.com/questions/20835531/struts-2-jquery-tab-navigation