Cool... I just did exactly the same thing!
Since others seem to need it, this might be worth refining over on wicket-stuff.

I did my version slightly different in that I used the existing one as a basis and created a PageTabbedPanel IPageTab and AbstractPageTab. The main difference is in the newTabContainer() method (and of course the support in the IPageTab interface).

I actually have two levels of tabs however in this current app and I have not satisfactorily resolved the second layer of tabs (obviously if I use the same thing on the second level, the tabs for the first are going to vanish). I was thinking that for multi layer page based tabs you could nest them.

Anyway, let me know if your interested, or if any other Wicket guru's are interested...

- Brill


On 9-Mar-09, at 1:32 PM, Christian Helmbold wrote:


Hello,

I've written a component which provides bookmarkable links for a tabbed panel. The link to the currend tab is disabled and the url to the default tab contains no tab information to keep URLs short.

It works so far, but since this is my first wicket component I'd like to know your suggestions to improve the code.

A possible improvement could be to replace the tab number by its name. So they would look like
http://some.url/app/PageX?tab=edit instead of
http://some.url/app/PageX?tab=1.
But to do this, it would be necessary to generate a map containing the tab names as keys and their indexes as values. This would be done on every request, because the tabbed panel is regenerated on every request. Is there a way to avoid the regeneration of the map? Maybe tab names in URLs are not really important, but I think a user would prefer a self-explanatory words in URLs.

I tried to use getPage().getPageParameters() in the constructor, but getPage() didn't work there. It works in the newLink(...) method. Why does it not work in the constructor?

Another question is: Is it a good idea to use this function within a component? If it is not a good idea, I have to add a page argument to the constructor instead of using getPage() in the newLink(...) method.

May this component be incompatible with other strategies than MixedParamUrlCodingStrategy? If this component is universal I'd like to contribute it to the wicket extensions sub project.


--------------------------------------------------------------------------------
package com.helmbold.wicket.components;

import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.extensions.markup.html.tabs.TabbedPanel;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;


public class BookmarkableTabbedPanel extends TabbedPanel
{

   private PageParameters pageParameters;
   private String tabParameterName = "tab";
   private int defaultTabIndex = 0;


 /**
  * Using this constructor the following defaults take effect:
  * <ul>
  *    <li>tabParameterName = "tab"</li>
  *    <li>defaultTabIndex = 0</li>
  * </ul>
    * @param id component id
    * @param tabs list of ITab objects used to represent tabs
* @param pageParameters Container for parameters to a requested page. A
  * parameter for the selected tab will be inserted.
    */
 public BookmarkableTabbedPanel(
         String id,
         List<ITab> tabs,
         PageParameters pageParameters)
 {
   super(id, tabs);
   this.pageParameters = pageParameters;

   if (pageParameters.containsKey(tabParameterName))
   {
     String tab = pageParameters.getString(tabParameterName);
     setSelectedTab(Integer.parseInt(tab));
   }
   else
     setSelectedTab(defaultTabIndex);
 }


   /**
    * @param id component id
    * @param tabs list of ITab objects used to represent tabs
* @param defaultTabIndex Set the tab to by displayed by default. The url * for this tab will not contain any tab specific information. If you want to * display the first tab by default, you can use the constructor without this
    * parameter.
* @param pageParameters Container for parameters to a requested page. A
  * parameter for the selected tab will be inserted.
    */
   public BookmarkableTabbedPanel(
       String id,
       List<ITab> tabs,
       int defaultTabIndex,
       String tabParameterName,
   PageParameters pageParameters)
   {
       this(id, tabs, pageParameters);
       this.defaultTabIndex = defaultTabIndex;
       setSelectedTab(defaultTabIndex);
       this.tabParameterName = tabParameterName;
   }


   @Override
 protected WebMarkupContainer newLink(String linkId, int index)
 {
   if (index == defaultTabIndex)
     pageParameters.remove(tabParameterName);
   else
     pageParameters.put(tabParameterName, "" + index);

   WebMarkupContainer link = new BookmarkablePageLink(
           linkId, getPage().getClass(), pageParameters);
   if (index == getSelectedTab())
     link.setEnabled(false);
   return link;
 }

}
--------------------------------------------------------------------------------

Regards,
Christian

--
http://www.groovy-forum.de






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to