Primefaces dialog framework doesn't show up

1.9k Views Asked by At

Yet another post on primefaces dialog framework.

I've been watching all of these previous posts:

Primefaces Dialog Framework - Not Working

primefaces dialog using dialog framework not popping up

Primefaces dialog framework not working while using ajax listener

I've been trying all of these but still the dialog just doesn't show up.\

I'm using primefaces 5.1.

Let me add some details.

Page with a button that should call the dialog:

<!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://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >

  <h:form>
      <p:commandButton 
         value="prova popup" 
         actionListener="#{codTribEr.chooseCodiceErario('/popup/codice-erario.xhtml')}">
      </p:commandButton>
  </h:form>

</html>

Java code:

package it.iwb.ubiss.poc.popup;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.context.RequestContext;

@ManagedBean(name="codTribEr")
@ViewScoped
public class CodiceTributoErario implements Serializable{

    private static final long serialVersionUID = 1L;

    public void chooseCodiceErario(String s) {
            RequestContext.getCurrentInstance().openDialog(s);
    }
}
1

There are 1 best solutions below

0
On

You use incorrect structure of JSF.

  1. You did not use JSF Standard tags(h:head, h:body).
  2. You pass cannot pass parameter through argument of actionListener because the actionListener only accept ActionEvent parameter. If you want to pass parameter through actionListener, you can achieve by f:attribute

The example code is shown below.

xhtml

<?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://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>prova popup</title>
    </h:head>

    <h:body>
        <h:form>
            <p:commandButton value="prova popup" 
                             actionListener="#{codTribEr.chooseCodiceErario}"
                             >
                <f:attribute name="url" value="/popup/codice-erario.xhtml" />
            </p:commandButton>
        </h:form>
    </h:body>

</html>

managedbean

package it.iwb.ubiss.poc.popup;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import org.primefaces.context.RequestContext;

@ManagedBean(name = "codTribEr")
@ViewScoped
public class CodiceTributoErario implements Serializable {

    private static final long serialVersionUID = 1L;

    public void chooseCodiceErario(ActionEvent event) {
        String url = (String)event.getComponent().getAttributes().get("url");
        System.out.println(url);
        RequestContext.getCurrentInstance().openDialog(url);
    }
}

codice-erario.xhtml

<?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://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>codice-erario</title>
    </h:head>

    <h:body>
        Show codice-erario.xhtml
    </h:body>

</html>