【问题标题】:PrimeFaces dialog does not show upPrimeFaces 对话框不显示
【发布时间】:2015-02-03 17:22:49
【问题描述】:

您好,我正在使用 PrimeFaces。当我遇到这个问题时。我想在单击保存按钮时显示我在表单中输入的值

XHTML 文件是

<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
          <h:head>
          <title>
          calender popup problem
          </title>


          </h:head>

<body>
    <h:form>
        <TABLE>
            <tr>
                <td><h:outputText value="*"/></td>
                <td><h:outputText value="COUPOUN NAME" /></td>
                <td><p:inputText id="coupounname"  maxlength="50" value="#{office.coupounname}"/></td>
            </tr>
            <tr style="padding-top: 10px">
                <td><h:outputText value="*"/></td>
                <td><h:outputText value="COUPOUN CODE" /></td>
                <td><p:inputText id="couponcode" value="#{office.coupouncode}"/></td>
            </tr>
            <tr style="padding-top:10px">
                <td><h:outputText value="*"/></td>
                <td><h:outputText value="COUPOUN DESCRIPTION"/></td>
                <td><p:inputTextarea id="coupoundes" value="#{office.coupouncode}"/></td>
            </tr>
            <tr style="padding-top: 10px">
                <td><h:outputText value= "*"/></td>
                <td><h:outputText value="Discount"/></td>

           <!-- <td>
                    <p:selectOneRadio id="radiobuttons" value="#{office.percentage}">
                    <f:selectItem itemLabel="in ruppes" itemValue="ByCash"/>
                    <f:selectItem itemLabel="inpercentage" itemValue="InPercentage"/>
                    </p:selectOneRadio> 
                </td> -->
            </tr>
            <tr>
                <td><h:outputText value="*"/></td>
                <td><h:outputText value="Validity"/></td>
                <td><p:calendar value="#{office.startdate}"/></td>
                <td><p:calendar value="#{office.enddate}"/></td>
            </tr> 
            <tr>
                <td><p:commandButton id="save" value="save" action="#{officebean.save}"/></td>
                <td><p:commandButton id="cancel" value="cancel"/></td>
            </tr>

        </TABLE>
    </h:form>
    <ui:include src="dialogs.xhtml"/>
</body>
</html>

对话框存储在文件中

<p:dialog id="listdialog" visible="${officebean.dialogvisible eq 'Bean'} " dynamic="true" minHeight="120"> 
    <h:form id="dialogform">
        <h:outputText value=" the value entered by the users were"/>
        <table>
            <tr>
                <td>name:=<h:outputText value="#{office.coupounname}"/></td>
                <td>code:<h:outputText value="#{officebean.dialogvisible}"/</td>
            </tr>
        </table>
    </h:form>
</p:dialog> 

现在是包含保存按钮操作的 bean 类,它设置使对话框可见的条件

@ManagedBean(name="officebean")
@RequestScoped
public class Officebean {
    private List<Office>officeList;
    private Office office;
    private String Dialogvisible;

    public void save() {
        Dialogvisible="Bean";   
    }

    public List<Office> getOfficeList() {
        return officeList;
    }

    public void setOfficeList(List<Office> officeList) {
        this.officeList = officeList;
    }

    public Office getOffice() {
        return office;
    }

    public void setOffice(Office office) {
        this.office = office;
    }

    public String getDialogvisible() {
        return Dialogvisible;
    }

    public void setDialogvisible(String dialogvisible) {
        Dialogvisible = dialogvisible;
    }
}

但是当点击保存按钮时没有显示对话框,任何持有都将不胜感激

【问题讨论】:

  • 并不是说它可能会有所不同,但为什么你有一个body 而不是h:body
  • 您在代码中的哪一点真正尝试打开对话框?

标签: jsf jsf-2 primefaces


【解决方案1】:

我猜你需要使用

&lt;h:body&gt; 而不是&lt;body&gt;

<p:dialog id="listdialog" widgetVar="listdialog".... >

<p:commandButton oncomplete="PF('listdialog').show()" ... />

也许从对话框中删除visible

【讨论】:

    【解决方案2】:

    试试

    <p:commandButton id="save" value="save" action="#{officebean.save}" update="listdialog"/>
    

    但如果你想显示为弹出窗口,你将不得不使用

    <p:commandButton id="save" value="save" action="#{officebean.save}" update="listdialog" oncomplete="#{p:widgetVar('listDialog')}.show();"/>
    

    【讨论】:

    • oncomplete="PF('listDialog').show();" 也可以。少一个 EL 评估 ;)
    • 更新后显示找不到组件列表对话框
    【解决方案3】:

    首先你必须知道,在你以某种方式调用 show() 函数之前,对话框不会显示...

    如果其他答案对您不起作用,也许您可​​以在 dialogs.xhtml 中添加:

    首先你必须在对话框中添加 widgetVar 变量,如下所示:

    <p:dialog id="listdialog" visible="${officebean.dialogvisible eq 'Bean'} " dynamic="true" minHeight="120" widgetVar="listdialog">
    

    然后在对话框之外类似:

    <p:remoteCommand id="rc1" name="showDialog"oncomplete="PF('listdialog').show();" />
    

    结束:

    <script type="text/javascript">
    showDialog();
    </script>
    

    这应该会在您打开 dialogs.xhtml 后立即打开您的对话框......

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-21
      • 1970-01-01
      • 2013-06-28
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      相关资源
      最近更新 更多