Boa tarde pessoal, to com uma dúvida provavelmente besta pra maioria aqui mas que sinceramente não consigo sair do lugar, já olhei diversos tutoriais e nada…
Criei um Entity chamado Empresa e pra ele um EmpresaAction, quando eu coloco o Action em Scope de conversation consigo editar, criar novo, mas se eu remover na lista a view não atualiza, se eu mudar o escopo pra EVENT eu consigo remover e a view da refresh, mas as propriedades não aparecem na edição, será que alguém pode me dar uma luz?
As classes tão abaixo:
Entity Empresa
@Entity
@Name("empresa")
@Table(name = "GS_EMPRESA")
public class Empresa implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "id_empresa")
private Long id;
@Column(name = "documento",length=14)
private String documento;
@Column(name = "razao_social",length=200)
private String razaoSocial;
@Column(name = "nome_fantasia",length=200)
private String nomeFantasia;
@Column(name = "inscricao_estadual",length=14)
private String inscricaoEstadual;
@Column(name = "contato",length=30)
private String contato;
@Column(name = "telefone", length=11)
private String telefone;
@Column(name = "email", length=90)
private String email;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDocumento() {
return documento;
}
public void setDocumento(String documento) {
this.documento = documento;
}
public String getInscricaoEstadual() {
return inscricaoEstadual;
}
public void setInscricaoEstadual(String inscricaoEstadual) {
this.inscricaoEstadual = inscricaoEstadual;
}
public String getRazaoSocial() {
return razaoSocial;
}
public void setRazaoSocial(String razaoSocial) {
this.razaoSocial = razaoSocial;
}
public String getNomeFantasia() {
return nomeFantasia;
}
public void setNomeFantasia(String nomeFantasia) {
this.nomeFantasia = nomeFantasia;
}
public String getContato() {
return contato;
}
public void setContato(String contato) {
this.contato = contato;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
EmpresaAction
@Name("empresaAction")
@Scope(ScopeType.CONVERSATION)
public class EmpresaAction {
@DataModelSelection
@Out(required=false)
private Empresa empresa = new Empresa();
@In
private EntityManager entityManager;
@Logger
private Log log;
@DataModel
private List<Empresa> empresas;
@End
public String salvarEmpresa(){
log.info("Salvando Empresa: #0", empresa.getRazaoSocial());
this.entityManager.merge(this.empresa);
this.empresa = new Empresa();
return "/empresa/controleEmpresa.xhtml";
}
@Begin
public String editarEmpresa(){
log.info("Editando Empresa #0", empresa.getRazaoSocial());
return "/empresa/editarEmpresa.xhtml";
}
@End
public String removerEmpresa(){
log.info("Removendo Empresa #0", empresa.getRazaoSocial());
this.entityManager.remove(empresa);
return "/empresa/controleEmpresa.xhtml";
}
@SuppressWarnings("unchecked")
@Factory("empresas")
public void populaEmpresas(){
log.info("Buscando Empresas do BD");
this.empresas = this.entityManager.createQuery("from Empresa e").getResultList();
}
public Empresa getEmpresa() {
return empresa;
}
public void setEmpresa(Empresa empresa) {
this.empresa = empresa;
}
public List<Empresa> getEmpresas() {
return empresas;
}
public void setEmpresas(List<Empresa> empresas) {
this.empresas = empresas;
}
}
editarEmpresa.xhtml
<!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:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="../layout/template.xhtml">
<ui:define name="body">
<rich:panel style="width:60%">
<f:facet name="header">
<h1>Editar Empresa</h1>
</f:facet>
<h:form>
<h:panelGrid style="width:90%">
<s:decorate template="../layout/edit.xhtml">
<ui:define name="label">Documento</ui:define>
<h:inputText value="#{empresaAction.empresa.documento}" />
</s:decorate>
<rich:separator lineType="solid" height="2"/>
<rich:spacer height="20"/>
<s:decorate template="../layout/edit.xhtml">
<ui:define name="label">Razão Social</ui:define>
<h:inputText value="#{empresaAction.empresa.razaoSocial}" />
</s:decorate>
<rich:separator lineType="solid" height="2"/>
<rich:spacer height="20"/>
<h:inputHidden value="#{empresaAction.empresa.id}" />
<h:commandButton value="Salvar" action="#{empresaAction.salvarEmpresa}" />
</h:panelGrid>
</h:form>
</rich:panel>
</ui:define>
</ui:composition>
</html>
controleEmpresa.xhtml
<!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:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="../layout/template.xhtml">
<ui:define name="body">
<rich:panel style="width:60%">
<f:facet name="header">
<h1>Controle de Empresas</h1>
</f:facet>
<h:form>
<rich:dataTable value="#{empresas}" var="e" style="width:60%">
<f:facet name="header">Empresas Cadastradas</f:facet>
<h:inputHidden value="#{empresaAction.empresa.id}" />
<rich:column>
<f:facet name="header">Documento</f:facet>
<h:outputText value="#{e.documento}" />
</rich:column>
<rich:column>
<f:facet name="header">Razão Social</f:facet>
#{e.razaoSocial}
</rich:column>
<rich:column>
<f:facet name="header">Nome Fantasia</f:facet>
#{e.nomeFantasia}
</rich:column>
<rich:column>
<f:facet name="header">I.E.</f:facet>
#{e.inscricaoEstadual}
</rich:column>
<rich:column>
<f:facet name="header">Contato</f:facet>
#{e.contato}
</rich:column>
<rich:column>
<f:facet name="header">Telefone</f:facet>
#{e.telefone}
</rich:column>
<rich:column>
<f:facet name="header">E-Mail</f:facet>
#{e.email}
</rich:column>
<rich:column>
<f:facet name="header"></f:facet>
<h:commandButton value="Editar" action="#{empresaAction.editarEmpresa()}" />
</rich:column>
<rich:column>
<f:facet name="header"></f:facet>
<h:commandButton value="Remover" action="#{empresaAction.removerEmpresa()}" />
</rich:column>
</rich:dataTable>
</h:form>
</rich:panel>
<rich:spacer height="20"/>
</ui:define>
</ui:composition>
</html>
Muito Obrigado!