1
I’m developing a jsf web application that I need to work with tabs (similar to Chrome). For this, I am using the tabview component of the first faces that has been very useful so far.
The problem is that I need to display a confirmation dialog before closing a certain tab. Does anyone know how I can do it?
Follow below the xhtml to date:
<?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");
}
}
Apparently it is not possible to do such an action without changing the code of the first faces. https://forum.primefaces.org/viewtopic.php?f=3&t=41298 e https://stackoverflow.com/questions/28833839/confirmdialog-on-tabclose-event.
– Marquezani
How could I make this change in the prime code?
– Kio Sam