What I try to achieve
I've got a rich:tabPanel
with switchType="client"
and one of the tabs has set its switchType
to ajax
because loading its data is an expensive operation. When I click on this Ajax Tab I want its title to be changed to Loading... to indicate that the click has been recognized. When it has finished loading, the title should switch back to Ajax Tab.
[Client Tab] [Ajax Tab]
<click on 'Ajax Tab'>
[Client Tab] [Loading...]
<wait...>
[Client Tab] [Ajax Tab]
<click on 'Client Tab'>
[Client Tab] [Ajax Tab]
Problem description
Actually, most of the described above works as expected, the only problem I have is, that when I navigate from the Ajax Tab to any other tab, the title of the Ajax Tab switches back to Loading...:
[Client Tab] [Ajax Tab]
<click on 'Ajax Tab'>
[Client Tab] [Loading...]
<wait...>
[Client Tab] [Ajax Tab]
<click on 'Client Tab'>
[Client Tab] [Loading...]
Research
I've found an issue in RichFaces' JIRA but this issue is fixed since version 3.2.1. Furthermore I've googled for a few hours but wasn't able to find any similar problems.
Environment
- Tomcat 7.0.30
- Mojarra 2.1.12
- RichFaces 4.2.2.Final
Code (reduced)
JSF
<ui:composition template="WEB-INF/templates/default.xhtml">
<ui:define name="content">
<h:form id="form">
<rich:tabPanel id="tabPanel" switchType="client">
<rich:tab id="clientTab">
<f:facet name="header">
<h:outputText value="Client Tab" />
</f:facet>
<h:outputText value="Foo" />
</rich:tab>
<rich:tab id="ajaxTab" switchType="ajax" status="ajaxTabStatus">
<f:facet name="header">
<a4j:status id="ajaxTabStatus">
<f:facet name="start">
<h:outputText value="Loading..." />
</f:facet>
<f:facet name="stop">
<h:outputText value="Ajax Tab" />
</f:facet>
</a4j:status>
</f:facet>
<h:outputText value="#{bean.value}" />
</rich:tab>
</rich:tabPanel>
</h:form>
</ui:define>
</ui:composition>
Backing Bean of Ajax Tab
@ManagedBean
@ViewScoped
public class Bean implements Serializable {
private static final long serialVersionUID = -8405248908693334970L;
private String value = "noValue";
private static final Logger log = LoggerFactory.getLogger(Bean.class);
@PostConstruct
public void init() {
log.info("Init bean.");
value = getDummyValueWithFakeDelay();
}
public String getValue() {
log.info("Get value.");
return value;
}
private String getDummyValueWithFakeDelay() {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
return DateFormat.getTimeInstance().format(new Date());
}
}
Update 1:
I've found out that the identifier (i mean that one you specify like <rich:someTag ... status="someStatus" />
) of an a4j:status
is not its id
but its name
attribute. So my a4j:status
is just for every Ajax request on that page. Giving it a name and using this named status does not work though, because nothing at all happens now.
<rich:tab id="ajaxTab" switchType="ajax" status="ajaxTabStatus">
<f:facet name="header">
<a4j:status id="ajaxTabStatus" name="ajaxTabStatus">
<f:facet name="start">
<h:outputText value="Loading..." />
</f:facet>
<f:facet name="stop">
<h:outputText value="Ajax Tab" />
</f:facet>
</a4j:status>
</f:facet>
<h:outputText value="#{bean.value}" />
</rich:tab>
Update 2:
I've also found another approach, using onbegin
and oncomplete
attributes with some code like:
<rich:tab id="ajaxTab" switchType="ajax"
onbegin="#{rich:component('ajaxTab')}.?"
oncomplete="#{rich:component('ajaxTab')}.?">
Well, as you see, I haven't found a way to manipulate the tab title yet (and I didn't find any useful documentation of what I can do with a rich:component).