Pass parameter to dialog in the same page

◇◆丶佛笑我妖孽 提交于 2019-12-29 07:25:27

问题


I have a page contains a form and other form nested in a dialog. I need to pass parameter to dialog when button clicked in the main form

<h:form>
<p:dataTable var="form" value="#{myBean.formList}">
     <p:commandButton id="selectProduct" 
                            update="selectProductForm" oncomplete="selectProductDlg.show()" 
                            image="ui-icon-" > 
                            <f:param name="formId" value="#{form.id}" />
                </p:commandButton>
</p:dataTable>
</h:form>

<p:dialog>
...<h:form>
<p:commandButton action="#{myBean.setSelected}"
                    update="main_form"
                    oncomplete="if(#{myBean.errorText == 'SUCCESS'}){ selectProductDlg.hide();}"
                    value="Sec">
                </p:commandButton>


i can not see formId in myBean with code:

if (form == null) {
            HttpServletRequest req = (HttpServletRequest) FacesContext
                    .getCurrentInstance().getExternalContext().getRequest();
            if(req.getParameter("formId") != null) {
                formId = Long.valueOf(req.getParameter("formId"));
            }
            if (formId != null && !"".equals(formId)) {
                form = formService.findById(formId);
            } 
        }

where am i wrong thanks


回答1:


Assuming that the bean is in the view scope, just set it as a bean property direclty in the action method of the command button in the datatable column.

<h:form>
  <p:dataTable var="form" value="#{myBean.formList}">
    <p:column>
      <p:commandButton id="selectProduct" 
                       action="#{myBean.setCurrentForm(form)}"
                       update="selectProductForm" oncomplete="selectProductDlg.show()" 
                       image="ui-icon-"> 
      </p:commandButton>
    </p:column>
  </p:dataTable>
</h:form>

<p:dialog>
  <h:form>
    <p:commandButton action="#{myBean.setSelected}"
                     update="main_form"
                     oncomplete="if(#{myBean.errorText == 'SUCCESS'}){ selectProductDlg.hide();}"
                     value="Sec">
    </p:commandButton>
  </h:form>
</p:dialog>

If you have a cancel button in the dialog, you need to let its action method set it to null.

There's no need to fiddle around with raw HTTP request parameters in POST requests. The <f:param> should as much as possible be used in GET requests only (e.g. <h:link>, <h:button>, etc).




回答2:


I have simply called the PDataTables's datamodel as shown below.

  1. IN the Java Bean I am refreshing the data from the backend receivedFdnsController.refreshData method.
    1. To refresh the data in the form I am calling datamodel refreshing as #{receivedFdnsController.newReceivedFdnsDataModel} after hiding the dialog. More details shown below.

Regards Khaleel



来源:https://stackoverflow.com/questions/8839224/pass-parameter-to-dialog-in-the-same-page

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