Primefaces对话框架没有显示出来

时间:2014-10-21 12:21:11

标签: primefaces dialog dialog-framework

关于 primefaces 对话框架的另一篇文章。

我一直在看所有这些帖子:

Primefaces Dialog Framework - Not Working

primefaces dialog using dialog framework not popping up

Primefaces dialog framework not working while using ajax listener

我一直在尝试所有这些但仍然没有显示对话框。\

我正在使用primefaces 5.1

让我补充一些细节。

带有应该调用对话框的按钮的页面:

<!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代码:

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 个答案:

答案 0 :(得分:0)

使用不正确的JSF结构。

  1. 您没有使用JSF标准代码(h:head,h:body)。
  2. 传递不能通过actionListener的参数传递参数,因为actionListener只接受ActionEvent参数。如果要通过actionListener传递参数,可以通过f:attribute
  3. 来实现

    示例代码如下所示。

    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>