PrimeFaces :: display p:Dialog to fill-in a form field, without reposting

↘锁芯ラ 提交于 2020-01-16 19:19:07

问题


I have a data-entry form that displays a number of fields (mostly p:inputText) for the user to provide. Some of these are LOVs so I display a p:dialog to allow the user to select the right value. The p:dialog is displayed by means of a p:commandLink next to the p:inputText. Main parts of code shown below:

<h:form id="parentForm">
    (...)
    <p:inputText value="#{CustomerCEVController.customer.municipality}" id="customerMncName"/>
    <p:commandLink type="button" onclick="MunicipalityDlg.show()" styleClass="ui-icon ui-icon-search"/>
    (...)
    <p:commandButton value="Submit"  id="save" actionListener="#{CustomerCEVController.saveButtonListener}" /> (...)
</h:form>

The problem is, whenever the user clicks on the p:commandLink to display the p:dialog (to allow him to select one of the values) the outer form goes through its lifecycle phases (restore view, apply request values, process validations, etc.) since the p:commandLink is placed inside an h:form. How can I implement this dialog-displaying functionality while avoiding posting the h:form with every dialog that the user opens?


回答1:


Just add "return false" as the last statement to onclick event handler. It prevents commandLink's default function (posting the form).




回答2:


Just add set the appendToBody attribute to true on <p:dialog>

<p:dialog header="Header Text" widgetVar="dlg" appendToBody="true">
   //Content
</p:dialog>

This appends the dialog as a child of the document body outside the parent form.



来源:https://stackoverflow.com/questions/11738355/primefaces-display-pdialog-to-fill-in-a-form-field-without-reposting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!