Boa noite galera, tudo bem?
Estou com um problema com primefaces e jsf 2, tenho um cadastro e uma lista logo abaixo do cadastro. Quando eu clico no botão da lista para editar um registro, atualizo meu objeto no managed bean e os campos do cadastro não são atualizados, porém quando eu dou um refresh na página, os campos são atualizado com o objeto que selecionei na lista.
O código está assim:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.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">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Cadastro de CD´s</title>
</h:head>
<h:body>
<f:view>
<h:form id="formCad">
<p:panel id="cadastro">
<f:facet name="header">
<h:outputText value="Cadastro de CD's" />
</f:facet>
<h:panelGrid columns="3">
<h:outputText value="Título:" />
<p:inputText id="txtTitulo" value="#{cdController.cd.titulo}"
required="true" requiredMessage="Campo Obirgatório." />
<p:message for="txtTitulo" />
<h:outputText value="Cantor:" />
<p:inputText id="txtCantor" value="#{cdController.cd.cantor}"
required="true" requiredMessage="Campo Obirgatório." />
<p:message for="txtCantor" />
<h:outputText value="Autor:" />
<p:inputText id="txtAutor" value="#{cdController.cd.autor}"
required="true" requiredMessage="Campo Obirgatório." />
<p:message for="txtAutor" />
<h:outputText value="Gênero:" />
<h:selectOneMenu id="somGenero"
value="#{cdController.cd.genero.id}" required="true"
requiredMessage="Campo Obrigatório.">
<f:selectItem itemLabel="--selecione--" />
<f:selectItems value="#{cdController.generos}" />
</h:selectOneMenu>
<p:message for="somGenero" />
<h:outputText value="Ano Lançamento:" />
<h:selectOneMenu id="somAnoLancamento"
value="#{cdController.cd.anoLancamento.id}" required="true"
requiredMessage="Campo Obrigatório.">
<f:selectItem itemValue="" itemLabel="--selecione--" />
<f:selectItems value="#{cdController.anosLancamento}" />
</h:selectOneMenu>
<p:message for="somAnoLancamento" />
<p:commandButton value="Salvar"
actionListener="#{cdController.save}" update="formCad" />
</h:panelGrid>
</p:panel>
<br />
<p:panel id="lista">
<f:facet name="header">
<h:outputText value="Lista de CD's" />
</f:facet>
<p:dataTable var="cd" value="#{cdController.cds}">
<p:column headerText="Título">
<h:outputText value="#{cd.titulo}" />
</p:column>
<p:column headerText="Cantor" style="width:200px">
<h:outputText value="#{cd.cantor}" />
</p:column>
<p:column headerText="Autor" style="width:200px">
<h:outputText value="#{cd.autor}" />
</p:column>
<p:column headerText="Gênero" style="width:80px">
<h:outputText value="#{cd.genero.genero}" />
</p:column>
<p:column headerText="Ano Lançamento" style="width:60px">
<h:outputText value="#{cd.anoLancamento.ano}" />
</p:column>
<p:column style="width:20px">
<p:commandButton image="ui-icon ui-icon-search" update="formCad"
immediate="true">
<f:setPropertyActionListener value="#{cd}"
target="#{cdController.cd}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
</f:view>
</h:body>
</html>
package br.com.virtualstore.controller;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import br.com.entidade.AnoLancamento;
import br.com.entidade.Cd;
import br.com.entidade.Genero;
@ManagedBean(name = "cdController")
@SessionScoped
public class CdController extends AbstractController implements Serializable {
private static final long serialVersionUID = -9145077893808064603L;
private Cd cd;
private List<SelectItem> generos;
private List<SelectItem> anosLancamento;
private List<Cd> cds;
public CdController() {
newForm();
}
private void newForm(){
this.cd = new Cd();
this.cd.setAnoLancamento(new AnoLancamento());
this.cd.setGenero(new Genero());
listGeneros();
listAnosLancamento();
listCds();
}
public void save(ActionEvent actionEvent) {
try {
getCdService().save(this.cd);
newForm();
} catch (Exception e) {
e.printStackTrace();
}
}
public void listCds() {
try {
this.cds = getCdService().getAll();
} catch (Exception e) {
e.printStackTrace();
}
}
private void listGeneros() {
try {
List<Genero> generos = getGeneroService().getAll();
if (generos != null && !generos.isEmpty()) {
this.generos = new ArrayList<SelectItem>();
for (Genero genero : generos) {
this.generos.add(new SelectItem(genero.getId(), genero.getGenero()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void listAnosLancamento() {
try {
List<AnoLancamento> anos = getAnoLancamentoService().getAll();
if (anos != null && !anos.isEmpty()) {
this.anosLancamento = new ArrayList<SelectItem>();
for (AnoLancamento anoLancamento : anos) {
this.anosLancamento.add(new SelectItem(anoLancamento.getId(), anoLancamento.getAno()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public List<Cd> getCds() {
return cds;
}
public void setCds(List<Cd> cds) {
this.cds = cds;
}
public Cd getCd() {
return cd;
}
public void setCd(Cd cd) {
this.cd = cd;
}
public List<SelectItem> getGeneros() {
return generos;
}
public void setGeneros(List<SelectItem> generos) {
this.generos = generos;
}
public List<SelectItem> getAnosLancamento() {
return anosLancamento;
}
public void setAnosLancamento(List<SelectItem> anosLancamento) {
this.anosLancamento = anosLancamento;
}
}
Já tentei de várias formas, mudei o update do botão de edição para atualizar o panel ou o panelgrid mas, nada!
Se alguém puder me ajudar desde já agradeço.
Obrigado.