【问题标题】:unselect the selected rows in a datatable取消选择数据表中的选定行
【发布时间】:2015-05-18 10:14:30
【问题描述】:

我正在使用单一选择模式处理数据表。我的问题是,当我刷新页面时,刷新之前相同的选定行保持刷新。 在这种情况下如何取消选择所有数据表行的任何想法。 感谢您帮助我解决这个问题。

这是我的数据表代码:

    <p:dataTable id="cars1" var="car"   widgetVar="carsTable" value="#{typePrimeManager.tprimes}" editable="false" style="margin-bottom:20px"  paginator="false"  selectionMode="single" selection="#{typePrimeManager.selectedtype}" rowKey="#{car.idPrime}">
    <p:ajax event="rowSelect" update=":form:cars2" />
    <p:ajax event="rowUnselect" listener="#{typePrimeManager.setSelectedtype(null)}" update=":form:cars2"/>
    <p:ajax event="rowUnselect" listener="#{typePrimeManager.setSelectedtype(null)}" update=":form:cars2"/>
    <p:column headerText="intitule des types">  
    <h:outputText value="#{car.intitulePrime}" />
    </p:column>
    </p:dataTable>

【问题讨论】:

  • 您将托管 bean 与 SessionScoped 一起使用?这保持价值不变。为了在页面刷新时清理选定的行,您也需要重置 selectedtype。
  • 没错,我使用的是 Scope("session")。但是如何重置所选类型?
  • 我建议您阅读此内容:stackoverflow.com/questions/7031885/… 如果您想继续使用 SessionScope 并重置 selectedrow,您必须清除 bean 中的 selectedtype
  • 谢谢。我真的很感激。
  • 不客气。考虑验证答案并欢迎使用 stackoverflow :)

标签: jsf jakarta-ee primefaces


【解决方案1】:

您将托管 bean 与 SessionScoped 一起使用?这保持价值不变。我建议您阅读此内容:How to choose the right bean scope?

如果您想继续使用 SessionScope 并重置选定的行,则必须清除 bean 中的 selectedtype

【讨论】:

    【解决方案2】:

    如果您必须拥有会话范围的 bean,则需要清除 DataTable 保存的值以引用所选项目,在您的情况下为 typePrimeManager.selectedtype

    因此,如果您将此值设置为 null 或任何不在 DataTable 数据源中的相同类型的对象,那么您的问题将得到解决,但您必须在重新加载页面之前执行此操作。要获取该事件,您可以使用预定义的 JSF 事件,例如 PreRenderView,来执行一个您应该清除所选值的方法,或者您可以定义一个 remoteCommand,它将调用适当的 bean 方法并使用 javascript 执行该 remoteCommand页面加载时。

    【讨论】:

      猜你喜欢
      • 2018-05-06
      • 2014-09-07
      • 1970-01-01
      • 2019-11-25
      • 2016-03-23
      • 1970-01-01
      • 2019-01-13
      • 2016-09-21
      • 2020-12-14
      相关资源
      最近更新 更多