【问题标题】:How to keep primefaces dialog open with javascript [duplicate]如何使用javascript保持primefaces对话框打开[重复]
【发布时间】:2016-12-02 09:05:49
【问题描述】:

primefaces 对话框有问题。我有自定义验证。 我创建了 javascript 方法以在自定义验证失败时保持对话框打开。 但虽然验证失败,但它一直在关闭。

这是我的代码:

function alertMsg()
    {
        var str1 = document.getElementById("templateForm:resultMsg").textContent;
        var str2 = "Duplicate name.";
        if(str1.localeCompare(str2) == 0)
        {
            alert("inside same!")
            PF(dlg).show(); //Although i try to keep open, this dialog always close.
        }
    }

 .....some code
<p:dialog header="Add" widgetVar="dlg" id="add" resizable="false" modal="true" closable="false" width="600px" >
<h:panelGrid columns="4" cellpadding="5" > 
    <p:outputLabel value="Name" style="width:130px;"/>
    <p:outputLabel  value=":" style="width:15px;"/>
    <h:inputText id="Name" value="#{Bean.Name}" styleClass="form-control"  style="width:300px;" required="true" requiredMessage="!" >
    </h:inputText>
    <h:outputText id="resultMsg1" value="Duplicate name." style="color:red; width:30px;"/>
</h:panelGrid>

<p:commandButton process="@parent" ajax="true" value="Save" onstart="alertMsg()"
                                    update= templateForm:resultMsg" action="#{Bean.save()}" styleClass="btn btn-danger">
                                    </p:commandButton>

</p:dialog>

【问题讨论】:

  • 尝试在你的 js 函数中使用return false;
  • 还是不行,继续关闭。
  • 我也认为你可能想要actionListener 而不是action,但我不是 100% 确定。
  • 它有效。 :D 非常感谢@Apostolos。 :)
  • 你能解释一下action和actionListener有什么不同吗?

标签: javascript jsf primefaces modal-dialog


【解决方案1】:

请使用actionLinstener 而不是action

你可以找到here两者的详细解释

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    相关资源
    最近更新 更多