【问题标题】:disable a particular button in a datatable, jsf禁用数据表中的特定按钮,jsf
【发布时间】:2012-09-11 05:20:31
【问题描述】:

我有一个包含两列的数据表 - 标题和操作 标题是从托管 bean 中的列表填充的,对于列表中的每个标题,数据表在 Action 列下都有一个名为 Confirm 的按钮。 当用户单击“确认”按钮时,会显示一个对话框,其中包含附加信息和另一个名为“提交”的按钮。

如果用户在该对话框中点击 Submit 按钮,则在 backing bean 中设置了一个变量 confirmDate,confirmDate 不为空,我需要禁用主数据表中 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>

【问题讨论】:

  • 我相信你的 backing bean 或者你应用 confirmDate 的方式有问题。你能贴出那些代码片段吗?
  • 在托管 bean 中,我正在做类似 public void updateNotificationConfirmDate(){ selectedNotification1.setConfirmDate((new Date(System.currentTimeMillis())).toString()); if(selectedNotification1.getConfirmDate() == null) setUserChecked(false);否则 setUserChecked(true);在弹出对话框的按钮中,上面的方法被调用

标签: jsf button datatable


【解决方案1】:

很难用您的代码说,也许您通过 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());
    }
}

【讨论】:

  • 感谢您的指点。我想我没有从对话框内的按钮更新通知列表。在挣扎了很长一段时间后,我决定仅在用户稍后未确认日期时才呈现按钮。
猜你喜欢
  • 2013-09-11
  • 2022-11-16
  • 2020-07-12
  • 1970-01-01
  • 2017-10-05
  • 2019-05-24
  • 2010-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多