rich:tabPanel is one of the richfaces components that we use very frequently in the project. One reason is that it allows us to do all processing on one page instead of multiple pages. It has its own drawbacks, but I think it's totally subjective to each individual and the type of applications.
Among the few properties of rich:tabPanel the 'name' and 'selectedTab' attributes are useful. Each tab can be given a name that you can references from other places and the 'name' attribute is just what you need. If you want to control which tab is active, then you will need to use 'selectedTab'. The process is simple, you can have a variable at the POJO or bean which can be an integer or string type. You can have that variable outjected by using @Out annotation. On the jsf page, all you need is selectedTab="#{varname}".
Now, I just mentioned that you can use both Integer and String type for the variable and it will work. Now there're times that an Integer type variable will cause some problems. For example, I gave each tab a dynamic names, which I did it by using object.hashCode() method. Each object is unique and therefore, the hashcode() will be unique. This will save you a lot of energy from brainstorming the names of the tabs if you have 10+ tabs. But when you use Integer variable for the selectedTab name, the page will crash everytime you try to do some processing. It is crashing at the Apply Phase because after you request an action, it'll try to restore the view and restore all the state variables and at that point, for some reasons, it cannot restore the selectedTab Integer variable. The workaround is to use String variable in this situation.
No comments:
Post a Comment