diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java index 3c3a8e8b1..cd0d7c84e 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/TabbedPanel.java @@ -34,6 +34,11 @@ import com.opensymphony.xwork2.util.ValueStack; * * The tabbedpanel widget is primarily an AJAX component, where each tab can either be local content or remote * content (refreshed each time the user selects that tab).
+ * If the useSelectedTabCookie attribute is set to true, the id of the selected tab is saved in a cookie on activation. + * When coming back to this view, the cookie is read and the tab will be activated again, unless an actual value for the + * selectedTab attribute is specified. + * If you want to use the cookie feature, please be sure that you provide a unique id for your tabbedpanel component, + * since this will also be the identifying name component of the stored cookie. * * * Examples @@ -92,7 +97,8 @@ public class TabbedPanel extends ClosingUIBean { protected String beforeSelectTabNotifyTopics; protected String afterSelectTabNotifyTopics; protected String disabledTabCssClass; - + protected String useSelectedTabCookie; + public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); } @@ -123,7 +129,10 @@ public class TabbedPanel extends ClosingUIBean { addParameter("afterSelectTabNotifyTopics", findString(afterSelectTabNotifyTopics)); if (disabledTabCssClass!= null) addParameter("disabledTabCssClass", findString(disabledTabCssClass)); - + if(useSelectedTabCookie != null) { + addParameter("useSelectedTabCookie", findString(useSelectedTabCookie)); + } + } @Override @@ -195,4 +204,11 @@ public class TabbedPanel extends ClosingUIBean { public void setDisabledTabCssClass(String disabledTabCssClass) { this.disabledTabCssClass = disabledTabCssClass; } + + @StrutsTagAttribute(required = false, defaultValue = "false", description = "If set to true, the id of the last selected " + + "tab will be stored in cookie. If the view is rendered, it will be tried to read this cookie and activate " + + "the corresponding tab on success, unless overridden by the selectedTab attribute. The cookie name is \"Struts2TabbedPanel_selectedTab_\"+id.") + public void setUseSelectedTabCookie( String useSelectedTabCookie ) { + this.useSelectedTabCookie = useSelectedTabCookie; + } } diff --git a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java index a7cb3ae86..f7046c04d 100644 --- a/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java +++ b/plugins/dojo/src/main/java/org/apache/struts2/dojo/views/jsp/ui/TabbedPanelTag.java @@ -42,8 +42,9 @@ public class TabbedPanelTag extends AbstractClosingTag { private String templateCssPath; private String beforeSelectTabNotifyTopics; private String afterSelectTabNotifyTopics; - protected String disabledTabCssClass; - + private String disabledTabCssClass; + private String useSelectedTabCookie; + public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { return new TabbedPanel(stack, req, res); } @@ -59,6 +60,7 @@ public class TabbedPanelTag extends AbstractClosingTag { tabbedPanel.setBeforeSelectTabNotifyTopics(beforeSelectTabNotifyTopics); tabbedPanel.setAfterSelectTabNotifyTopics(afterSelectTabNotifyTopics); tabbedPanel.setDisabledTabCssClass(disabledTabCssClass); + tabbedPanel.setUseSelectedTabCookie(useSelectedTabCookie); } public void setSelectedTab(String selectedTab) { @@ -88,4 +90,8 @@ public class TabbedPanelTag extends AbstractClosingTag { public void setDisabledTabCssClass(String disabledTabCssClass) { this.disabledTabCssClass = disabledTabCssClass; } + + public void setUseSelectedTabCookie( String useSelectedTabCookie ) { + this.useSelectedTabCookie = useSelectedTabCookie; + } } diff --git a/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl b/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl index a2b66a656..88c735ca9 100644 --- a/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl +++ b/plugins/dojo/src/main/resources/template/ajax/tabbedpanel.ftl @@ -21,6 +21,30 @@ */ --> +<#if parameters.useSelectedTabCookie?exists && parameters.useSelectedTabCookie=="true"> + +#if> +