2016-05-16 12 views
1

Ich bin ein Anfänger Java Entwickler, und ich versuche, eine grundlegende CRUD auf PrimeFaces 5.2 auf einem Projekt, das ich bereits auf Hibernate 5 hatte laufen zu bekommen. Die Tabelle zeigt ok, aber die Der modale Dialog wird nicht angezeigt, wenn ich auf eine der Schaltflächen klicke. Ich habe viele Dinge aus dem Internet ausprobiert, aber alles scheint in Ordnung zu sein, also bin ich wirklich festgefahren.Modal Dialog nicht auf PrimeFaces 5

Ich schätze wirklich jedes Licht, das Sie auf dieses abwerfen können. Vielen Dank!

index.html

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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.org/ui"> 
<h:head> 
    <title>Gerenciador de Tarefas</title> 
</h:head> 
<h:body> 
    <p:layout fullPage="true"> 
     <p:layoutUnit position="north" width="200" header="Atividades" resizable="true" closable="true" collapsible="true"> 
      <h:form prependId="false"> 
       <p:commandLink value="Nova Tarefa" actionListener="#{tarefaController.prepararAdicionarTarefa}" update="infosTarefa" oncomplete="dialogGerTarefa.show()"/> 
      </h:form> 
     </p:layoutUnit> 

     <p:layoutUnit position="center"> 
      <h1>Gerenciador de Tarefas</h1> 
      <br/> 
      <h:form prependId="false"> 
       <p:dataTable id="tabela" var="tarefa" value="#{tarefaController.listarTarefas}"> 
        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Título"/> 
         </f:facet> 
         <h:outputText value="#{tarefa.titulo}" /> 
        </p:column> 
        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Prazo de execução"/> 
         </f:facet> 
         <h:outputText value="#{tarefa.prazo_execucao}"/> 
        </p:column> 
        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Detalhes"/> 
         </f:facet> 
         <h:outputText value="#{tarefa.detalhes}"/> 
        </p:column> 
        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Responsável"/> 
         </f:facet> 
         <h:outputText value="#{tarefa.responsavel}"/> 
        </p:column> 
        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Urgente"/> 
         </f:facet> 
         <h:outputText value="#{tarefa.urgente}"/> 
        </p:column> 
        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Status"/> 
         </f:facet> 
         <h:outputText value="#{tarefa.status}"/> 
        </p:column> 
        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Data de conclusao"/> 
         </f:facet> 
         <h:outputText value="#{tarefa.data_conclusao}"/> 
        </p:column> 

        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Descricao da conclusao"/> 
         </f:facet> 
         <h:outputText value="#{tarefa.descricao_conclusao}"/> 
        </p:column> 

        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Alterar"/> 
         </f:facet> 
         <p:commandButton actionListener="#{tarefaController.prepararAlterarTarefa}" ajax="false" value="Alterar" update="infosTarefa" oncomplete="dialogGerTarefa.show()"/> 
        </p:column> 

        <p:column> 
         <f:facet name="header"> 
          <h:outputText value="Excluir"/> 
         </f:facet> 
         <h:commandLink action="#{tarefaController.excluirTarefa}" value="Excluir"/> 
        </p:column> 
       </p:dataTable> 
      </h:form> 
     </p:layoutUnit> 
    </p:layout> 

    <p:dialog header="Gerencia de Tarefa" widgetVar="dialogGerTarefa" resizable="false" modal="true" width="500"> 
     <h:form prependId="false"> 
      <h:panelGrid id="infosTarefa" columns="2" style="margin-bottom:10px"> 

       <h:outputLabel for="titulo" value="Título:" /> 
       <h:inputText id="titulo" value="#{tarefaController.tarefa.titulo}"/> 

       <h:outputLabel for="prazo_execucao" value="Prazo de execução:" /> 
       <h:inputText id="prazo_execucao" value="#{tarefaController.tarefa.prazo_execucao}"/> 

       <h:outputLabel for="detalhes" value="Detalhes:" /> 
       <h:inputText id="detalhes" value="#{tarefaController.tarefa.detalhes}"/> 

       <h:outputLabel for="responsavel" value="Responsavel:" /> 
       <h:inputText id="responsavel" value="#{tarefaController.tarefa.responsavel}"/> 

       <h:outputLabel for="urgente" value="Urgente:" /> 

       <h:selectOneMenu id="urgente" value="#{tarefaController.tarefa.urgente}"> 
        <f:selectItem itemLabel="nao" itemValue="0"/> 
        <f:selectItem itemLabel="sim" itemValue="1"/> 
       </h:selectOneMenu> 

       <h:outputLabel for="status" value="Status:" /> 
       <h:inputText id="status" value="#{tarefaController.tarefa.status}"/> 

       <h:outputLabel for="data_conclusao" value="Data de conclusao:" /> 
       <h:inputText id="data_conclusao" value="#{tarefaController.tarefa.data_conclusao}"/> 

       <h:outputLabel for="descricao_conclusao" value="Descricao da conclusao:" /> 
       <h:inputText id="descricao_conclusao" value="#{tarefaController.tarefa.descricao_conclusao}"/> 

       <p:commandButton update="tabela" oncomplete="dialogGerTarefa.hide();" actionListener="#{tarefaController.adicionarTarefa}" value="Inserir Tarefa"/> 
       <p:commandButton update="tabela" oncomplete="dialogGerTarefa.hide();" actionListener="#{tarefaController.alterarTarefa}" value="Alterar Tarefa"/> 

      </h:panelGrid> 
     </h:form> 
    </p:dialog> 

</h:body> 

tarefaController.java

package br.com.listadetarefas.controller; 

import java.util.List; 

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.faces.event.ActionEvent; 
import javax.faces.model.DataModel; 
import javax.faces.model.ListDataModel; 

import br.com.listadetarefas.jpa.TarefaDao; 
import br.com.listadetarefas.model.Tarefa; 

@ManagedBean 
@SessionScoped 
public class TarefaController { 

    private Tarefa tarefa; 
    private DataModel listaTarefas; 

    public DataModel getListarTarefas() { 
     List<Tarefa> lista = TarefaDao.listaTarefasComFiltro("Todas"); 
     listaTarefas = new ListDataModel(lista); 
     return listaTarefas; 
    } 

    public Tarefa getTarefa() { 
     return tarefa; 
    } 

    public void setTarefa(Tarefa tarefa) { 
     this.tarefa = tarefa; 
    } 

    public void prepararAdicionarTarefa(ActionEvent actionEvent) { 
     tarefa = new Tarefa(); 
    } 

    public void prepararAlterarTarefa(ActionEvent actionEvent) { 
     tarefa = (Tarefa) (listaTarefas.getRowData()); 
    } 

    public String excluirTarefa() { 

     Tarefa tarefaTemp = (Tarefa) (listaTarefas.getRowData()); 
     TarefaDao.remove(tarefaTemp.getId()); 
     return "index"; 

    } 

    public void adicionarTarefa(ActionEvent actionEvent) { 

     TarefaDao.adiciona(tarefa); 

    } 

    public void alterarTarefa(ActionEvent actionEvent) { 

     TarefaDao.resolve(tarefa); 

    } 

} 

tarefa.java

package br.com.listadetarefas.model; 

import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.Id; 

@Entity 
public class Tarefa { 

    @Id 
    @GeneratedValue 
    private int id; 

    private String titulo; 
    private String prazo_execucao; 
    private String detalhes; 
    private String responsavel; 
    private boolean urgente; 
    private String status; 
    private String data_conclusao; 
    private String descricao_conclusao; 

    public Tarefa() { 
     this.status = "aberta"; 
    } 

    public String getTitulo() { 
     return titulo; 
    } 
    public void setTitulo(String titulo) { 
     this.titulo = titulo; 
    } 
    public String getPrazo_execucao() { 
     return prazo_execucao; 
    } 
    public void setPrazo_execucao(String prazo_execucao) { 
     this.prazo_execucao = prazo_execucao; 
    } 
    public String getDetalhes() { 
     return detalhes; 
    } 
    public void setDetalhes(String detalhes) { 
     this.detalhes = detalhes; 
    } 
    public String getResponsavel() { 
     return responsavel; 
    } 
    public void setResponsavel(String responsavel) { 
     this.responsavel = responsavel; 
    } 
    public boolean isUrgente() { 
     return urgente; 
    } 
    public void setUrgente(boolean urgente) { 
     this.urgente = urgente; 
    } 
    public String getStatus() { 
     return status; 
    } 
    public void setStatus(String status) { 
     this.status = status; 
    } 
    public String getData_conclusao() { 
     return data_conclusao; 
    } 
    public void setData_conclusao(String data_conclusao) { 
     this.data_conclusao = data_conclusao; 
    } 
    public String getDescricao_conclusao() { 
     return descricao_conclusao; 
    } 
    public void setDescricao_conclusao(String descricao_conclusao) { 
     this.descricao_conclusao = descricao_conclusao; 
    } 
    public int getId() { 
     return id; 
    } 
    public void setId(int id) { 
     this.id = id; 
    } 
} 

Antwort

1

ich mir sieht aus, als das Hauptproblemist 10 auf der Befehlsschaltfläche. Entferne das. Es gibt keine oncomplete -callback, wenn Sie eine vollständige Anfrage (nur mit Ajax).

Ersetzen Sie auch dialogGerTarefa.show() durch PF('dialogGerTarefa').show() (und ähnlich für hide()). Die erste ist eine alte Syntax.

Auch würde ich prependId="false" überall entfernen. More reading. Sie müßten dem Formular im Dialog eine feste ID geben und beispielsweise mit updaten (naja, Sie könnten auch einfach update=":dialogformid" machen).

+0

Ok, es hat funktioniert! = D Nur der prependId = "false" hat den Code tatsächlich kaputt gemacht, ich denke ... Ohne dass es einwandfrei funktioniert hat, vielen Dank! – Lajotas

+0

Wenn ich Sie noch etwas fragen kann, habe ich tatsächlich versucht, diese erste Layout-Einheit auf der "linken" Position anzuzeigen, aber es wird nicht rendern. Ist etwas falsch, außer zu layoutUnit position = "left" zu wechseln? – Lajotas

+1

Großartig :-) Sie könnten auch mehr Hauptkomponenten verwenden, da Sie es sowieso einfügen .. zum Beispiel selectOneMenu, commandLink. Sie sind nur besser und mit mehr Optionen. Und vielleicht zu CDI-Beans wechseln, wenn Ihr Server dies unterstützt. Aber das ist nur Optionals –