Não achei o motivo do erro, mas quando o Dialog abre, simplesmente não carrega as informações do livro.
<?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:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="_template.xhtml">
<ui:define name="titulo">
Ring
</ui:define>
<ui:define name="conteudo">
<h:form id="ringForm">
<p:ring id="basic" value="#{livroBean.livros}" var="livro">
<p:outputPanel style="text-align: center;" layout="block">
#{livro.titulo}
<br />
<p:commandButton update=":ringForm:livroDetail" icon="ui-icon-search" title="View" oncomplete="PF('livroDialog').show();">
<f:setPropertyActionListener value="#{livro}" target="#{livroBean.livro}" />
</p:commandButton>
</p:outputPanel>
</p:ring>
<p:dialog id="livroDialog" header="Informações do Livro" widgetVar="livroDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" width="300">
<p:outputPanel id="livroDetail" style="text-align:center" layout="block">
<p:panelGrid columns="2" rendered="#{not empty livroBean.livro}" columnClasses="value" style="width:100%;">
<f:facet name="header">
#{livroBean.livro.titulo}
</f:facet>
<h:outputText value="Preço" />
<h:outputText value="#{livroBean.livro.preco}" />
<h:outputText value="ISBN" />
<h:outputText value="#{livroBean.livro.isbn}" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
</html>
package br.com.caelum.livraria.bean;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import br.com.caelum.livraria.dao.DAO;
import br.com.caelum.livraria.modelo.Autor;
import br.com.caelum.livraria.modelo.Livro;
@ManagedBean
@ViewScoped
public class LivroBean implements Serializable {
private static final long serialVersionUID = 1L;
private Livro livro = new Livro();
private Integer autorId;
private Integer livroId;
private List<Livro> livros;
public void setAutorId(Integer autorId) {
this.autorId = autorId;
}
public Integer getAutorId() {
return autorId;
}
public Livro getLivro() {
return livro;
}
public Integer getLivroId() {
return livroId;
}
public void setLivroId(Integer livroId) {
this.livroId = livroId;
}
public List<Livro> getLivros() {
DAO<Livro> dao = new DAO<Livro>(Livro.class);
if(this.livros == null) this.livros = dao.listaTodos();
return livros;
}
public List<Autor> getAutores() {
return new DAO<Autor>(Autor.class).listaTodos();
}
public List<Autor> getAutoresDoLivro() {
return this.livro.getAutores();
}
public void gravarAutor() {
Autor autor = new DAO<Autor>(Autor.class).buscaPorId(this.autorId);
this.livro.adicionaAutor(autor);
System.out.println("Escrito por: " + autor.getNome());
}
public void gravar() {
System.out.println("Gravando livro " + this.livro.getTitulo());
if (livro.getAutores().isEmpty()) {
FacesContext.getCurrentInstance().addMessage("autor",
new FacesMessage("Livro deve ter pelo menos um Autor."));
return;
}
DAO<Livro> dao = new DAO<Livro>(Livro.class);
if (this.livro.getId() == null) {
dao.adiciona(this.livro);
this.livros = dao.listaTodos();
} else {
dao.atualiza(this.livro);
}
this.livro = new Livro();
}
public void carregar(Livro livro) {
System.out.println("Carregando livro " + livro.getTitulo());
this.livro = livro;
}
public void remover(Livro livro) {
System.out.println("Removendo livro " + livro.getTitulo());
new DAO<Livro>(Livro.class).remove(livro);
}
public void removerAutorDoLivro(Autor autor) {
this.livro.removeAutor(autor);
}
public String formAutor() {
System.out.println("Chamanda do formulário do Autor.");
return "autor?faces-redirect=true";
}
public void comecaComDigitoUm(FacesContext fc, UIComponent component,
Object value) throws ValidatorException {
String valor = value.toString();
if (!valor.startsWith("1")) {
throw new ValidatorException(new FacesMessage(
"ISBN deveria começar com 1"));
}
}
public void carregarLivroPelaId() {
this.livro = new DAO<Livro>(Livro.class).buscaPorId(livroId);
}
public boolean filtrarPreco(Object valorColuna, Object valorFiltro, Locale locale) {
String textoDigitado = (valorFiltro == null) ? null : valorFiltro.toString().trim();
System.out.println("Filtrando pelo " + textoDigitado + ", Valor do elemento: " + valorColuna);
if (textoDigitado == null || textoDigitado.equals("")) {
return true;
}
if (valorColuna == null) {
return false;
}
try {
Double precoDigitado = Double.valueOf(textoDigitado);
Double precoColuna = (Double) valorColuna;
return precoColuna.compareTo(precoDigitado) < 0;
} catch (NumberFormatException e) {
return false;
}
}
}
FASE: RESTORE_VIEW 1
FASE: APPLY_REQUEST_VALUES 2
FASE: PROCESS_VALIDATIONS 3
FASE: UPDATE_MODEL_VALUES 4
FASE: INVOKE_APPLICATION 5
dez 29, 2016 3:26:44 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
ADVERTÊNCIA: /ring.xhtml @23,87 target="#{livroBean.livro}": Property 'livro' not writable on type br.com.caelum.livraria.bean.LivroBean
javax.el.PropertyNotWritableException: /ring.xhtml @23,87 target="#{livroBean.livro}": Property 'livro' not writable on type br.com.caelum.livraria.bean.LivroBean
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:211)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIData.broadcast(UIData.java:1108)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.PropertyNotWritableException: Property 'livro' not writable on type br.com.caelum.livraria.bean.LivroBean
at javax.el.BeanELResolver$BeanProperty.write(BeanELResolver.java:314)
at javax.el.BeanELResolver$BeanProperty.access$100(BeanELResolver.java:274)
at javax.el.BeanELResolver.setValue(BeanELResolver.java:120)
at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
at org.apache.el.parser.AstValue.setValue(AstValue.java:202)
at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:257)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
... 33 more
dez 29, 2016 3:26:44 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
GRAVE: javax.el.PropertyNotWritableException: /ring.xhtml @23,87 target="#{livroBean.livro}": Property 'livro' not writable on type br.com.caelum.livraria.bean.LivroBean
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:211)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIData.broadcast(UIData.java:1108)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.PropertyNotWritableException: Property 'livro' not writable on type br.com.caelum.livraria.bean.LivroBean
at javax.el.BeanELResolver$BeanProperty.write(BeanELResolver.java:314)
at javax.el.BeanELResolver$BeanProperty.access$100(BeanELResolver.java:274)
at javax.el.BeanELResolver.setValue(BeanELResolver.java:120)
at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
at org.apache.el.parser.AstValue.setValue(AstValue.java:202)
at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:257)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
... 33 more