简体   繁体   English

带有表单中字段的Prime Faces对话框

[英]Prime faces dialog with fields in the form

I've got a form that is a simply created. 我有一个简单创建的表单。 What I want to do is show my dialog with the name (ie: the value from the inputField ) on click. 我想做的是在单击时显示带有名称(即inputField的值)的对话框。 I realize the dialog happens BEFORE the action of the commandButton , so I'm trying to figure out how to get what the value is at that moment: 我意识到对话框是在commandButton动作之前发生的,所以我试图弄清楚那时如何获取值:

<h:form id="myForm">
  <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" id="confirmDialog">
    <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
    <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
  </p:confirmDialog>

  <p:inputField id="field" value="#{myBean.myName}"/>
  <p:commandButton value="Create" update=":myForm" actionListener="#{myBean.sayHi}"> 
    <p:confirm header="Confirmation" message="Is your name actually #{myBean.myName}?" icon="ui-icon-alert" />
  </p:commandButton>
</h:form>

Right now the dialog box just shows an empty string. 现在,对话框仅显示一个空字符串。 How would we do that? 我们将如何做?

With something like a selectOneMenu , I could just add an AJAX event. 使用selectOneMenu类的东西,我可以添加一个AJAX事件。 Do I really need something similar with an input field? 我真的需要与输入字段类似的东西吗?

There is no point in submitting the value before confirmation just to use it in the confirmDialog so the way to go is to use onclick event of the commandButton to change the message="Is your name actually #{myBean.myName}?" 在确认之前仅在confirmDialog使用该值就没有意义,因此方法是使用commandButton的onclick事件来更改message="Is your name actually #{myBean.myName}?" using javascript. 使用javascript。

check this code, it works fine: 检查此代码,它可以正常工作:

<h:form id="myForm">
  <p:growl id="msg" />
  <p:inputText id="field" value="#{indexBacking.input}" widgetVar="fieldWv"/>

  <p:commandButton id="cmd01" value="Create" onclick="showConfirm();"/>

  <p:confirmDialog showEffect="fade" hideEffect="fade" id="confirmDialog" widgetVar="confirmDialogWv">
    <f:facet name="message">
      <div id="confirmMessage"></div>
    </f:facet>
    <p:commandButton value="Yes" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" actionListener="#{indexBacking.sayHi()}" update="@form"/>
    <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" onclick="PF('confirmDialogWv').hide();"/>
  </p:confirmDialog>

  <script type="text/javascript"> 
    function showConfirm() {
        PF('confirmDialogWv').show();
        $('#confirmMessage').empty();
        $('#confirmMessage').append("<p>Is your name actually [" + PF('fieldWv').jq.val() + "]?</p>");
      }
   </script>
 </h:form>

please notice that I was forced to ditch the behavior and to use the p:confirmDialog as a standard dialog to do this. 请注意,我被迫放弃这种行为,并使用p:confirmDialog作为标准对话框来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM