Using "Tab" in wicket
Tab Panel items are separated with the different tab and different tabs show different component which are associated with them. Only one tab will be activated at a time.
In the previous section of Wicket example you have learned about creating modal panel, template website, autocompleter and some more. Now in this part of Wicket tutorial you will learn how to create tabbed panel in Wicket.
In this example of creating Tab panel in wicket we have created three tab panels and these three panels are showing different associated components with them. In our example we have created following six files to create a tabbed panel which consists of three tabs "first", "second" and "third".
- TabbedApplication.java
- TabbedPanelPage.java
- TabbedPanelPage.html
- TabbedPanelPage$TabPanel1.html
- TabbedPanelPage$TabPanel2.html
- TabbedPanelPage$TabPanel3.html
TabbedApplication.java file will call TabbedPanelPage.java. Here is the example code of TabbedApplication.java as follows:
TabbedApplication.java
package com.roseindia.wicket;
|
TabbedPanelPage.java
package com.roseindia.wicket;
|
TabbedPanelPage class defines three inner class TabPanel1, TabPanel2 and TabPanel3 which are called when user click on these tabs. Corresponding to TabbedPanelPage class HTML file is as follows:
TabbedPanelPage.html
<html>
|
According to inner classes of TabbedPanelPage we have to create three more HTML files as well . Here is the code of these three files as follows:
TabbedPanelPage$TabPanel1.html
<html> <wicket:panel> <br/> This is tab-panel 1 </wicket:panel> </html> |
TabbedPanelPage$TabPanel2.html
<html> <wicket:panel> <br/> This is tab-panel 2 </wicket:panel> </html> |
TabbedPanelPage$TabPanel3.html
<html> <wicket:panel> <br/> This is tab-panel 3 </wicket:panel> </html> |
We have to do corresponding XML file entry into the web.xml file to call TabbedApplication class. Here is the code fragment which is to be included into :
<filter> <filter-name> TabbedApplication </filter-name> <filter-class> org.apache.wicket.protocol.http.WicketFilter </filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>com.roseindia.wicket.TabbedApplication</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> </filter> <filter-mapping> <filter-name> TabbedApplication </filter-name> <url-pattern> /wicket/tab/* </url-pattern> </filter-mapping> |
Output: