I'm a beginner with JSF
, web development, and I'm having a problem using the Dialog
component, PrimeFaces
, within DataTable
.
The idea was this: We have a gift list for a bridal shower, the party guest chooses the present that wants to give, and clicks the Escolher
button, from there it opens a Dialog
Containing a OuputLabel
and a InputText
containing the guest name, and a button to confirm that it will save the selected gift, the person's name and phone number.
I made a test code without a database, just a prototype of what it will be, however it is showing inconsistency, as image and commandButton
, is not calling method teste
of ManagedBean
:
---ManagedBean---
importjava.io.Serializable;importjavax.faces.bean.ManagedBean;importjavax.faces.bean.ViewScoped;@ManagedBean@ViewScopedpublicclassConfirmarPresenteBeanimplementsSerializable{privatestaticfinallongserialVersionUID=1L;privateStringnome;privateStringtelefone;publicvoidteste(){System.out.println("Nome: " + this.nome);
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
}
--- XHTML ---
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><ui:insert name="titulo">Chacolate de Panela</ui:insert></title>
<h:outputStylesheet library="css" name="sistema.css" />
</h:head>
<h:body>
<script>
function tratarConfirmacaoPresente(args) {
if (!args.validationFailed) {
confirmarPresenteDialog.hide();
}
}
</script>
<div id="container">
<h:form id="dataTable">
<p:dataTable value="#{listaPresentesBean.presentes}" var="presente"
sortBy="#{presente.nomePresente}" rows="10" paginator="true"
paginatorPosition="bottom" rowsPerPageTemplate="10, 15, 20">
<p:column headerText="Lista de Presentes">
<h:outputText value="#{presente.nomePresente}" />
</p:column>
<p:column headerText="" width="20">
<p:commandButton value="Escolher" id="botaoEscollher"
onclick="confirmarPresenteDialog.show(); return false;" />
<!-- Dialog -->
<p:dialog header="Confirmar Presente"
widgetVar="confirmarPresenteDialog" modal="true"
resizable="false">
<h:panelGroup id="confirmacaoPanel">
<p:messages />
<h:panelGrid columns="2">
<p:outputLabel value="Nome" for="nome" />
<p:inputText id="nome" required="true"
value="#{confirmarPresenteBean.nome}" />
</h:panelGrid>
<p:commandButton value="Confirmar"
update="confirmacaoPanel"
action="#{confirmarPresenteBean.teste}" />
</h:panelGroup>
</p:dialog>
</p:column>
</p:dataTable>
</h:form>
</div>
</h:body>
</html>