I have an In-cell editin dataTable and I want to add a "insert" button.
When I press this button a new dialog is show.
In this dialog I have a "Save" button.
When I press this button, the information in this form is passed to a bean and inserted in the database using JPA.
The problem is that when I press the Save button, the dialog is closed, but the information in the datatable are not updated.
If I press ctrl+F5, I can see the new register as a row, but it I press the add button again, the dialog is opened with the information that I provided before.
May someone help me?
This is the .xhtml page:
Code: Select all
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<f:view>
<script type="text/javascript">
function handleConfirmaRequest(xhr, status, args) {
if(args.validationFailed || !args.loggedIn) {
jQuery('#dlg_ins_seg_grupos').effect("shake", { times:3 }, 100);
} else {
dlg_ins_seg_grupos.hide();
// jQuery('#loginLink').fadeOut();
}
}
</script>
<ui:insert name="padraocabecalho">
<ui:include src="/resources/templates/padraocabecalhopfp.xhtml" />
</ui:insert>
<ui:insert name="menubar">
<ui:include src="/resources/templates/menubar.xhtml" />
</ui:insert>
<h:form id="form_gruposseguranca">
<p:growl id="growl" showDetail="true" sticky="true" rendered="true"/>
<p:dataTable id="segGruposList" var="c" value="#{segGruposController.listaobj}"
rowEditListener="#{segGruposController.dataTableOnRowEdit}"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,20,40" >
<f:facet name="header">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center" width="100%">
<h:outputText value="Grupos de Segurança"/>
</td>
<td align="right">
<p:commandButton image="#{request.contextPath}/resources/images/add.png" onclick="dlg_ins_seg_grupos.show()" />
</td>
</tr>
</table>
</f:facet>
<p:column headerText="Código" style="width:350px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{c.segGruposCodigo}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{c.segGruposCodigo}" disabled="true" readonly="true" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Descrição" style="width:350px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{c.segGruposDescri}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{c.segGruposDescri}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Opções">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
<p:growl id="growl2" showDetail="true" life="3000" />
<p:dialog id="Ldlg_ins_seg_grupos" header="Login" widgetVar="dlg_ins_seg_grupos" modal="false" height="180">
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="descricao" value="Descrição do Grupo: " />
<h:inputText value="#{segGruposController.classeobj.segGruposDescri}"
id="descricao" required="true" label="descricao" />
<f:facet name="footer">
<p:commandButton value="Salvar" style="text-align:left"
action="#{segGruposController.salvar}"
oncomplete="dlg_ins_seg_grupos.hide();" update="segGruposList" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
</f:view>
</html>
Code: Select all
package br.com.sitic.sitic.seguranca.factory.backing;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.primefaces.event.RowEditEvent;
import br.com.sitic.sitic.seguranca.action.SegGruposDAO;
import br.com.sitic.sitic.sistema.model.SegGrupos;
public class SegGruposController implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private SegGrupos classeobj;
private List<SegGrupos> listaobj;
private Integer seggruposcodigo;
@SuppressWarnings("rawtypes")
private DataModel model;
public SegGruposController(){
classeobj = new SegGrupos();
listaobj = new ArrayList<SegGrupos>();
popularListaobj(listaobj);
// SegGruposSmall = new ArrayList<SegGrupos>();
// classeobj = new SegGrupos();
}
public Integer getSeggruposcodigo() {
return seggruposcodigo;
}
public void setSeggruposcodigo(Integer seggruposcodigo) {
this.seggruposcodigo = seggruposcodigo;
}
@SuppressWarnings("unchecked")
private void popularListaobj(List<SegGrupos> plistaobj){
SegGruposDAO objdao = new SegGruposDAO();
plistaobj.addAll(objdao.exibir());
}
public List<SegGrupos> getListaobj(){
return listaobj;
}
public SegGrupos getClasseobj(){
return classeobj;
}
public void setClasseobj(SegGrupos classeobj){
this.classeobj = classeobj;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public DataModel getModel(){
SegGruposDAO objdao = new SegGruposDAO();
model = new ListDataModel(objdao.exibir());
return model;
}
public int getCount(){
SegGruposDAO objdao = new SegGruposDAO();
return objdao.exibir().size();
}
public String adicionar(SegGrupos classeobj) {
this.classeobj = classeobj;
return "Adicionar";
}
public String deletar(SegGrupos classeobj){
SegGruposDAO objdao = new SegGruposDAO();
objdao.deletar(classeobj);
return "Deletar";
}
public String salvar() {
// System.out.println("getSeggrupos().getSegGruposCodigo(): "+getSeggrupos().getSegGruposCodigo());
SegGruposDAO objdao = new SegGruposDAO();
if (classeobj.getSegGruposCodigo() == null) {
objdao.adicinar(classeobj);
}
else {
objdao.alterar(classeobj);
}
return "Salvar";
}
public void dataTableOnRowEdit(RowEditEvent event){
SegGruposDAO objdao = new SegGruposDAO();
SegGrupos sclasseobj =(SegGrupos) event.getObject();
System.out.println("Codigo: "+sclasseobj.getSegGruposCodigo()+", Descrição: "+sclasseobj.getSegGruposDescri());
objdao.alterar(sclasseobj);
}
}