2012-01-12 117 views
11

我有一個頁面包含一個窗體和嵌套在對話框中的其他形式。 我需要的參數傳遞給對話框時,按鈕在主窗體點擊將參數傳遞給對話框在同一頁

<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> 


我看不到formId在爲myBean與代碼:

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); 
      } 
     } 

我在哪裏錯了 謝謝

回答

17

假設該bean在視圖範圍內,只需將它設置爲一個bea n數據表列中命令按鈕的操作方法中的屬性direclty。

<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> 

如果在對話框中取消按鈕,你需要讓其操作方法將其設置爲null

沒有必要在POST請求中擺弄原始的HTTP請求參數。 <f:param>應儘可能地僅用於GET請求(例如<h:link>,<h:button>等)。

+0

非常感謝,我曾經以爲我不能傳遞參數的操作方法,現在我編輯的代碼和它的工作 – merveotesi 2012-01-13 08:50:25

+0

不客氣。 – BalusC 2012-01-13 12:32:19

-1

我簡單地稱爲PDataTables的數據模型,如下所示。

  1. 在Java Bean中,我正在刷新後端receivedFdnsController.refreshData方法中的數據。
    1. 要在隱藏對話框後刷新窗體中的數據,我正在調用datamodel刷新爲#{receivedFdnsController.newReceivedFdnsDataModel}。更多細節如下所示。

問候 Khaleel

+0

請嘗試弄清楚爲什麼您的建議編輯隊列已滿,以及爲什麼它沒有處理,因爲該帖子目前沒有任何有用的表單。 – 2017-03-24 10:45:41