I am learning/using JSF 2.0 (Sun Mojarra) now and I want to have a tabbed pane in my webapp (single tabs could named be General, Detail1,Detail2,...).
How do I achieve this? I haven't found any documetation for this so far :(
I am learning/using JSF 2.0 (Sun Mojarra) now and I want to have a tabbed pane in my webapp (single tabs could named be General, Detail1,Detail2,...).
How do I achieve this? I haven't found any documetation for this so far :(
There are numerous of useful components for JSF, which provide more or less fancier tab panels (among many others). RichFaces, IceFaces, OpenFaces (and PrimeFaces as mentioned). Each of these is fairly complete and you typically can't mix-and-match, so see the demo sites for each one, and pick the one you like. I like RichFaces, but that's in part because it was the default on Seam2 which is where I first learned JSF. frameworks
JSF is only a "backbone" framework if I may call it that way. Out of the box it gives you very few components as this was the intention of the creators - they wanted others to extend this framework with their own work (as long as they follow the set standards, that is). Now you can either write your own components or use frameworks such as PrimeFaces, ICEFaces, RichFaces etc. which already have a number of components.
Consider using an existing component library.
PrimeFaces has a TabView with ability to add effects, and dynamic content.
In order to implement PrimeFaces, follow the instructions
Others have already hinted it: Mojarra is a basic JSF implementation. It offers the minimum set of mandatory components to cover the most of existing HTML elements (forms, input fields and tables). Since HTML does not offer a tabbed panel in a single element, the basic JSF implementation won't do that as well.
A tabbed panel is basically a bunch of links (or buttons) and panels which are to be toggled hidden/visible. To represent links, you usually use the HTML
<a>
element. To represent panels, you usually use the HTML<div>
element. To toggle show/hide either there are basically 2 ways:Print every panel to response, but hide all other panels using CSS
display: none
and use JavaScript to toggle the visiblity by setting the new panel todisplay: block
and the old panel todisplay: none
.Or, print the requested panel to the response conditionally. Which panel has been requested can be be determined by request parameters in the links (or buttons).
Here's a basic copy'n'paste'n'runnable example of way 1:
You can of course replace
<a>
by<h:outputLink>
and<div>
by<h:panelGroup layout="block">
and so on, but as long as you don't need to bind it in the with the backing bean and/or JSF component tree, then just plain HTML is perfectly valid as well and has less overhead.You just have to bring
<ui:repeat>
in to repeat the tabs and the panels "dynamically" based on some list. Also don't forget to throw in a good shot of CSS to make it all look like tasty. This is basically where the most of the work goes in.This is after all basically also what those 3rd party component libraries like PrimeFaces, RichFaces and IceFaces are doing. They all provide the desired functionality in a single component which does all the repeating and eye-candiness job. PrimeFaces for example has a
<p:tabView>
, RichFaces a<rich:tabPanel>
, IceFaces an<ice:panelTabSet>
and so on.