From d0e719075c0b81685144953c14902ebe567acf6a Mon Sep 17 00:00:00 2001 From: Michele Silva Date: Wed, 8 Feb 2012 15:28:35 -0200 Subject: [PATCH] Corrigidos erros no upload (nullpointer). --- nbproject/build-impl.xml | 2 - nbproject/genfiles.properties | 6 +- nbproject/project.properties | 2 - nbproject/project.xml | 4 - .../simdecs/mb/bn/CharacterEncodingFilter.java | 2 +- .../ufcspa/simdecs/mb/bn/FileUploadController.java | 2 + .../org/ufcspa/simdecs/mb/bn/RedeEditBean.java | 81 +++++++++++-------- .../org/ufcspa/simdecs/mb/bn/RedeUploadBean.java | 5 +- web/WEB-INF/web.xml | 2 +- 9 files changed, 55 insertions(+), 51 deletions(-) diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 28fab05..f534b70 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -691,7 +691,6 @@ exists or setup the property manually. For example like this: - @@ -717,7 +716,6 @@ exists or setup the property manually. For example like this: - diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 7c59915..dc32fd1 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=2c4c42bc +build.xml.data.CRC32=aed63b6a build.xml.script.CRC32=9f680c47 build.xml.stylesheet.CRC32=651128d4@1.36.1.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=2c4c42bc -nbproject/build-impl.xml.script.CRC32=d3f674de +nbproject/build-impl.xml.data.CRC32=aed63b6a +nbproject/build-impl.xml.script.CRC32=da75e33b nbproject/build-impl.xml.stylesheet.CRC32=b7883b1f@1.36.1.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index 8781252..00bfdb4 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -45,7 +45,6 @@ file.reference.junit-4.1.jar=lib/junit-4.1.jar file.reference.log4j-1.2.12.jar=lib/log4j-1.2.12.jar file.reference.logkit-1.0.1.jar=lib/logkit-1.0.1.jar file.reference.primefaces-3.1-SNAPSHOT.jar=lib/primefaces-3.1-SNAPSHOT.jar -file.reference.servlet-api-2.3.jar=lib/servlet-api-2.3.jar file.reference.unbbayes-4.10.4-1s.jar=lib/unbbayes-4.10.4-1s.jar file.reference.xalan-2.7.0.jar=lib/xalan-2.7.0.jar file.reference.xml-apis-1.0.b2.jar=lib/xml-apis-1.0.b2.jar @@ -80,7 +79,6 @@ javac.classpath=\ ${file.reference.junit-4.1.jar}:\ ${file.reference.log4j-1.2.12.jar}:\ ${file.reference.logkit-1.0.1.jar}:\ - ${file.reference.servlet-api-2.3.jar}:\ ${file.reference.unbbayes-4.10.4-1s.jar}:\ ${file.reference.xalan-2.7.0.jar}:\ ${file.reference.xml-apis-1.0.b2.jar} diff --git a/nbproject/project.xml b/nbproject/project.xml index c7c6a47..33ba691 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -79,10 +79,6 @@ WEB-INF/lib - ${file.reference.servlet-api-2.3.jar} - WEB-INF/lib - - ${file.reference.unbbayes-4.10.4-1s.jar} WEB-INF/lib diff --git a/src/java/org/ufcspa/simdecs/mb/bn/CharacterEncodingFilter.java b/src/java/org/ufcspa/simdecs/mb/bn/CharacterEncodingFilter.java index 59e382b..eec00b0 100644 --- a/src/java/org/ufcspa/simdecs/mb/bn/CharacterEncodingFilter.java +++ b/src/java/org/ufcspa/simdecs/mb/bn/CharacterEncodingFilter.java @@ -15,7 +15,7 @@ public class CharacterEncodingFilter implements Filter, Serializable @Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { req.setCharacterEncoding("UTF-8"); - //resp.setCharacterEncoding("UTF-8"); + resp.setCharacterEncoding("UTF-8"); chain.doFilter(req, resp); } diff --git a/src/java/org/ufcspa/simdecs/mb/bn/FileUploadController.java b/src/java/org/ufcspa/simdecs/mb/bn/FileUploadController.java index 7415116..47fc3b3 100644 --- a/src/java/org/ufcspa/simdecs/mb/bn/FileUploadController.java +++ b/src/java/org/ufcspa/simdecs/mb/bn/FileUploadController.java @@ -14,6 +14,7 @@ import javax.xml.bind.JAXBException; import org.primefaces.event.FileUploadEvent; import org.primefaces.model.UploadedFile; import org.ufcspa.simdecs.entities.Nodo; +import org.ufcspa.simdecs.entities.PerguntaNodo; import org.ufcspa.simdecs.entities.Rede; import org.ufcspa.simdecs.mb.DefaultManagedBean; import unbbayes.io.exception.LoadException; @@ -68,6 +69,7 @@ public class FileUploadController extends DefaultManagedBean { Nodo nodo = new Nodo(); nodo.setNome(prs_node.getName()); nodo.setRede(rede); + nodo.setPerguntas(new ArrayList()); nodes.add(nodo); } rede.setNodos(nodes); diff --git a/src/java/org/ufcspa/simdecs/mb/bn/RedeEditBean.java b/src/java/org/ufcspa/simdecs/mb/bn/RedeEditBean.java index dc1a5d3..15b4be3 100644 --- a/src/java/org/ufcspa/simdecs/mb/bn/RedeEditBean.java +++ b/src/java/org/ufcspa/simdecs/mb/bn/RedeEditBean.java @@ -88,18 +88,23 @@ public class RedeEditBean extends DefaultManagedBean { } public void addPergunta() { - try { - em.getTransaction().begin(); - } finally { - PerguntaNodo pergunta = new PerguntaNodo(); - pergunta.setTexto(""); - pergunta.setNodo(selectedNodo); - pergunta.setRespostas(new ArrayList()); - selectedNodo.getPerguntas().add(pergunta); - em.persist(pergunta); - em.getTransaction().commit(); + if (selectedNodo != null) { + try { + em.getTransaction().begin(); + } finally { + PerguntaNodo pergunta = new PerguntaNodo(); + pergunta.setTexto(""); + pergunta.setNodo(selectedNodo); + pergunta.setRespostas(new ArrayList()); + selectedNodo.getPerguntas().add(pergunta); + em.persist(pergunta); + em.getTransaction().commit(); + } + addInfoMessage("Pergunta Adicionada", "Pergunta adicionada com sucesso."); + } else { + addErrorMessage("Pergunta não adicionada", "Não existe nodo selecionado."); } - addInfoMessage("Pergunta Adicionada", "Pergunta adicionada com sucesso."); + } public void removePergunta(PerguntaNodo pergunta) { @@ -114,19 +119,23 @@ public class RedeEditBean extends DefaultManagedBean { } public void addResposta() { - try { - em.getTransaction().begin(); - } finally { - RespostaNodo resposta = new RespostaNodo(); - resposta.setTexto(""); - resposta.setPergunta(selectedPergunta); - resposta.setPesoMinimo(0); - resposta.setPesoMaximo(1); - selectedPergunta.getRespostas().add(resposta); - em.persist(resposta); - em.getTransaction().commit(); + if (selectedPergunta != null) { + try { + em.getTransaction().begin(); + } finally { + RespostaNodo resposta = new RespostaNodo(); + resposta.setTexto(""); + resposta.setPergunta(selectedPergunta); + resposta.setPesoMinimo(0); + resposta.setPesoMaximo(1); + selectedPergunta.getRespostas().add(resposta); + em.persist(resposta); + em.getTransaction().commit(); + } + addInfoMessage("Resposta adicionada", "Resposta adicionada com sucesso."); + } else { + addErrorMessage("Resposta não adicionada", "Não existe pergunta selecionada."); } - addInfoMessage("Resposta adicionada", "Resposta adicionada com sucesso."); } public void removeResposta(RespostaNodo resposta) { @@ -141,18 +150,22 @@ public class RedeEditBean extends DefaultManagedBean { } public void addNodo() { - try { - em.getTransaction().begin(); - } finally { - Nodo nodo = new Nodo(); - nodo.setNome(""); - nodo.setRede(rede); - nodo.setPerguntas(new ArrayList()); - rede.getNodos().add(nodo); - em.persist(nodo); - em.getTransaction().commit(); + if (rede != null) { + try { + em.getTransaction().begin(); + } finally { + Nodo nodo = new Nodo(); + nodo.setNome(""); + nodo.setRede(rede); + nodo.setPerguntas(new ArrayList()); + rede.getNodos().add(nodo); + em.persist(nodo); + em.getTransaction().commit(); + } + addInfoMessage("Nodo adicionado", "Nodo adicionado com sucesso."); + } else { + addErrorMessage("Nodo não adicionado", "Não existe rede selecionada."); } - addInfoMessage("Nodo adicionado", "Nodo adicionado com sucesso."); } diff --git a/src/java/org/ufcspa/simdecs/mb/bn/RedeUploadBean.java b/src/java/org/ufcspa/simdecs/mb/bn/RedeUploadBean.java index 98707d6..c683379 100644 --- a/src/java/org/ufcspa/simdecs/mb/bn/RedeUploadBean.java +++ b/src/java/org/ufcspa/simdecs/mb/bn/RedeUploadBean.java @@ -6,8 +6,6 @@ package org.ufcspa.simdecs.mb.bn; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.persistence.Query; @@ -44,7 +42,6 @@ public class RedeUploadBean extends DefaultManagedBean { public void setSelectedItems(Rede[] selectedItems) { this.selectedItems = selectedItems; - Logger.getLogger(RedeUploadBean.class.getName()).log(Level.INFO, "Set selected items."); } public SimdecsDataModel getSelectableItems() { @@ -59,7 +56,7 @@ public class RedeUploadBean extends DefaultManagedBean { for (Rede item : selectedItems) { em.remove(item); } - addInfoMessage("Rede removida!", "Rede Bayesiana removida com sucesso!"); + addInfoMessage("Rede removida", "Rede Bayesiana removida com sucesso."); em.getTransaction().commit(); } } diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 6233712..9f0863d 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -2,7 +2,7 @@ javax.faces.PROJECT_STAGE - Release + Production Faces Servlet -- 1.7.6.4