Modal dialog not showing on PrimeFaces 5

Tomaz Fernandes

I´m a beginner java developer, and I´m trying to get a basic CRUD running on PrimeFaces 5.2 on top of a project I already had on Hibernate 5. The table shows ok, but the modal dialog doesn´t show when I click any of the buttons. I´ve tried many things from around the web but everything seems to be ok, so I´m really stuck.

I really appreciate any light you can shed on this. Thank you!

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;
    }
}
Jaqen H'ghar

I looks to me as the main problem is ajax="false" on the commandButton. Remove that. There is no oncomplete-callback when you do a full request (only with ajax).

Also replace dialogGerTarefa.show() with PF('dialogGerTarefa').show() (and similar for hide()). The first is an old syntax.

Also I'd remove prependId="false" everywhere. More reading. You'd have to give the form in the dialog a fixed id, and update with for example update=":dialogformid:infosTarefa" (well you might as well just do update=":dialogformid").

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Showing a modal dialog and getting results

From Dev

TeamCity with showing a modal dialog box

From Dev

primefaces commandlink wont show modal dialog

From Dev

Show a modal dialog using primefaces commandLink in a growl

From Dev

Primefaces dialog scrollbar not showing up below the header

From Dev

HTML5 Modal Dialog is showing shortly on page load, how can i stop this?

From Dev

Showing multiple templates within a single modal dialog

From Dev

primefaces modal dialog: How to disable the 'X' close button

From Dev

primefaces modal dialog: How to disable the 'X' close button

From Dev

Primefaces commandButton is not showing dialog after ajax form refresh

From Dev

hold submit for modal dialog confirmation in mvc 5

From Dev

Who should be responsible for showing a modal dialog with a log in form?

From Dev

How to hide the body scroll bar when showing scroll is in modal dialog?

From Dev

Showing modal dialog when navigating away from a tab in TabStrip

From Dev

Modal Dialog Box not showing in ASP.NET web

From Dev

Modal RCP Dialog not modal

From Dev

MVC 5 / Bootstrap App - Modal Dialog Auto expand?

From Dev

Updating a dialog with ajax of primefaces?

From Dev

Primefaces dialog event for unmaximize?

From Dev

Primefaces Dialog Framework Liferay

From Dev

Primefaces Dialog Update Mechanisms

From Dev

Primefaces dialog event for unmaximize?

From Dev

primefaces dialog is not working

From Dev

BarChart Labels in primefaces not showing

From Dev

How to change bootstrap modal dialog so that it has no animation while showing but fade outs slowly?

From Dev

Open Dialog Box on Primefaces Error

From Dev

Primefaces - CommandButton in dialog is refreshing page

From Dev

Primefaces dialog close button not working

From Dev

Primefaces dialog only working once

Related Related

  1. 1

    Showing a modal dialog and getting results

  2. 2

    TeamCity with showing a modal dialog box

  3. 3

    primefaces commandlink wont show modal dialog

  4. 4

    Show a modal dialog using primefaces commandLink in a growl

  5. 5

    Primefaces dialog scrollbar not showing up below the header

  6. 6

    HTML5 Modal Dialog is showing shortly on page load, how can i stop this?

  7. 7

    Showing multiple templates within a single modal dialog

  8. 8

    primefaces modal dialog: How to disable the 'X' close button

  9. 9

    primefaces modal dialog: How to disable the 'X' close button

  10. 10

    Primefaces commandButton is not showing dialog after ajax form refresh

  11. 11

    hold submit for modal dialog confirmation in mvc 5

  12. 12

    Who should be responsible for showing a modal dialog with a log in form?

  13. 13

    How to hide the body scroll bar when showing scroll is in modal dialog?

  14. 14

    Showing modal dialog when navigating away from a tab in TabStrip

  15. 15

    Modal Dialog Box not showing in ASP.NET web

  16. 16

    Modal RCP Dialog not modal

  17. 17

    MVC 5 / Bootstrap App - Modal Dialog Auto expand?

  18. 18

    Updating a dialog with ajax of primefaces?

  19. 19

    Primefaces dialog event for unmaximize?

  20. 20

    Primefaces Dialog Framework Liferay

  21. 21

    Primefaces Dialog Update Mechanisms

  22. 22

    Primefaces dialog event for unmaximize?

  23. 23

    primefaces dialog is not working

  24. 24

    BarChart Labels in primefaces not showing

  25. 25

    How to change bootstrap modal dialog so that it has no animation while showing but fade outs slowly?

  26. 26

    Open Dialog Box on Primefaces Error

  27. 27

    Primefaces - CommandButton in dialog is refreshing page

  28. 28

    Primefaces dialog close button not working

  29. 29

    Primefaces dialog only working once

HotTag

Archive