Question regarding the onclick attribute of <rich:tab>
I have the following code:
<rich:tabPanel switchType="client">
<rich:tab name="tab1" label="tab1" onclick="alert('Hello');">
...
</rich:tab>
<rich:tab name="tab2" label="tab2" onclick="alert('Hi');">
...
</rich:tab>
</rich:tabPanel>
This code will generate a panel with 2 tab headers, like that:
+------+ +------+
| tab1 | | tab2 |
+ +-+------+--------------------------+
| |
| Content of my Tab goes here... |
| |
+------------------------------------------+
Regarding the code used, I would expect to see a JavaScript alert saying Hi
if I click on the tab2
header.
However, nothing is displayed, and I just switch to the second tab.
In fact, if I click on the content of the tab, the alert message is displayed.
I am a bit confused regarding this behavior.
Question #1 Is this behavior normal? In others words, the onclick
refers to the click event on the content and not on the tab header.
Indeed, if I look at this post and this related defect, it does not seem to be开发者_如何学编程 correct...
Question #2 If this behavior is normal, how can I set a different onclick
behavior for each tab? Indeed, if I set the onclick
on the <rich:tabPanel>
instead of the <rich:tab>
component, the onclick
javascript function will always be executed.
I am using Richfaces 3.3.2.GA, JSF 1.2 + Facelets, Java 1.6
After browsing the Richfaces forum and especially this bug, as well as the code of this component, I found that there is a onlabelclick
attribute that does exaclty what I want to do.
So the answer for my first question is Yes, and the working code for the second question is:
<rich:tabPanel switchType="client">
<rich:tab name="tab1" label="tab1" onlabelclick="alert('Hello');">
...
</rich:tab>
<rich:tab name="tab2" label="tab2" onlabelclick="alert('Hi');">
...
</rich:tab>
</rich:tabPanel>
I wasn't aware of this attribute because the site and the developer guide of Richfaces do not tell anything about them, and my Eclipse IDE + JBoss Tools plugin didn't include them in the autocompletion mechanism.
精彩评论