I'm developing a web application in jsf that I need to work with tabs (similar to chrome). For that, I'm using the tabview component of primefaces that has been very useful so far.
The problem is that I need to display a closing commit dialog before the closing of a particular tab. Does anyone know how I can do this?
Below is the xhtml so far:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form id="frm">
<p:growl id="message" showDetail="true" />
<p:tabView id="abas">
<p:ajax event="tabClose" listener="#{beanAba.fecharAba}" />
<p:tab title="Aba 1" closable="true">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="Alguma Coisa 1" />
</h:panelGrid>
</p:tab>
<p:tab title="Aba 2" closable="true">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="Alguma Coisa 2 " />
</h:panelGrid>
</p:tab>
<p:tab title="Aba 3" closable="true">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="Alguma Coisa 3" />
</h:panelGrid>
</p:tab>
</p:tabView>
<p:confirmDialog global="true" id="dlg" >
<p:commandButton value="Yes" type="button" />
<p:commandButton value="No" type="button"/>
</p:confirmDialog>
</h:form>
</h:body>
</html>
And here's my Bean:
package com.controller.aba;
import java.io.Serializable;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;
@Named(value = "beanAba")
@ViewScoped
public class BeanAba implements Serializable {
public void fecharAba() {
RequestContext context = RequestContext.getCurrentInstance();
FacesContext fContext = FacesContext.getCurrentInstance();
context.execute("PF('dlg').show();");
fContext.addMessage(null, new FacesMessage("Aba Removida!"));
context.update("frm:message");
}
}