2012-09-07 41 views
2

我有一個包含兩列的數據表 - 標題和操作 標題從託管bean中的列表填充,並且對於列表中的每個標題,數據表具有名爲Confirm的按鈕在Action欄下。 當用戶單擊確認按鈕時,會顯示一個對話框,其中包含其他信息以及另一個名爲Submit的按鈕。禁用數據表中的特定按鈕,jsf

如果用戶點擊該對話框中的Submit按鈕,在backing bean中設置變量confirmDate,confirmDate的值不爲null,我需要禁用主數據表中Action列下的特定Confirm按鈕。現在,如果我禁用它,所有確認按鈕都會被禁用。如何禁用所選的確認按鈕。非常感謝你對此的幫助。

主數據表

<h:panelGrid id="notificationList" width="100%"> 
<h:panelGroup >       
    <p:dataTable var="dt" value="# 
    {myBean.listAll}" id="titles" rowKey="#{dt.id}">         

    <f:facet name="header"> 
     <h:outputText value = "Title List"/>            
    </f:facet> 

    <p:column headerText ="Title"> 
     <h:outputText value="#{dt.title}"/> 
    </p:column> 

    <p:column headerText="Action"> 

     <p:commandButton id="nID"              
     value="Confirm"  
     oncomplete="myDialog.show();" 
     process="@this" 
     disabled= "#{not empty dt.confirmDate} 
     update="@form"> 

     <f:setPropertyActionListener value="#{dt}" target="# 
      {myBean.selectedTitle}"/>          
     </p:commandButton> 
    </p:column> 
</p:dataTable> 
</h:panelGroup> 
</h:panelGrid> 
+0

我相信你有什麼不對您的支持bean或您應用confirmDate的方式。你能發佈這些代碼片段嗎? – fischermatte

+0

在託管bean中,我正在做一些類似於public void updateNotificationConfirmDate()的方法selectedNotification1.setConfirmDate((new Date(System.currentTimeMillis()))。toString()); if(selectedNotification1.getConfirmDate()== null) setUserChecked(false); else setUserChecked(true); }在彈出對話框中的按鈕上面的方法正在調用 santa029

回答

0

硬盤與您的代碼的說,也許你通過listAll檢索所有dt對象相同的對象。你如何設置清單?

總之這應該工作(簡體):

<p:dialog widgetVar="dlg"> 
    <p:commandButton value="Submit" action="#{myBean.updateNotificationConfirmDate}" oncomplete="dlg.hide()" 
     update="notificationList" /> 
</p:dialog> 
<p:dataTable id="notificationList" var="dt" value="#{myBean.tableData}"> 
    <p:column> 
     <p:commandButton value="Confirm" process="@this" disabled="#{!empty dt.confirmDate}" update="@form" 
      oncomplete="dlg.show();"> 
      <f:setPropertyActionListener value="#{dt}" target="#{myBean.selectedTitle}" /> 
     </p:commandButton> 
    </p:column> 
</p:dataTable> 

而且支持bean(無論您的DT是:)):

@ManagedBean 
@ViewScoped 
public class MyBean { 
    private List<DT> tableData = new ArrayList<DT>(); 
    private DT selectedTitle; 

    public MyBean() { 
     tableData.add(new DT(1L, "title1", null)); 
     tableData.add(new DT(2L, "title2", null)); 
     tableData.add(new DT(3L, "title3", null)); 
     tableData.add(new DT(4L, "title4", null)); 

    } 

    public DT getSelectedTitle() { 
     return selectedTitle; 
    } 

    public void setSelectedTitle(DT selectedTitle) { 
     this.selectedTitle = selectedTitle; 
    } 

    public List<DT> getTableData() { 
     return tableData; 
    } 

    public void updateNotificationConfirmDate() { 
     selectedTitle.setConfirmDate(Calendar.getInstance()); 
    } 
} 
+0

感謝指針。我想我沒有更新notificationList從對話框裏的按鈕。經過相當長時間的努力之後,我決定只在用戶以後沒有確認日期時才渲染按鈕。 santa029