【问题标题】:Toggle Image on select in JSF extendedDataTable在 JSF 扩展数据表中选择图像时切换
【发布时间】:2012-11-09 18:24:35
【问题描述】:

我正在尝试根据是否在扩展数据表中选择了行来获取图像来回交换。我能够以非活动状态显示图像,但不知道如何切换它。下面是表定义代码:

<rich:extendedDataTable style="width: 800px; height: 150px;" 
rowClasses="Row0,Row1" value="#{myBean.exceptions}" var="exception"
selectionMode="single" id="Table" selection="#{myBean.exceptionSelection}">
<a4j:ajax event="selectionchange" listener="#{myBean.rowListener}" render=""/>

这是我要切换其图像的列。思路是在同一个目录下换成一张名为filledRadioButton的图片:

<rich:column id="selected_col" label="Selection">
<f:facet name="header">
<a4j:commandLink value="Selection" render="table"/>
</f:facet>
<h:graphicImage value="../resources/img/emptyRadioButton.jpg"/>
</rich:column>

谢谢

【问题讨论】:

    标签: jsf-2 richfaces


    【解决方案1】:

    您可以使用dataTable 的ajaxKeys 属性来专门引用一行(或多行)以进行ajax 更新。所以要实现这一点:

    1. 将数据表的ajaxKeys 属性绑定到支持bean 中的Set&lt;Integer&gt;。该集合将保存唯一的 id 类型值,这些值将引用数据表中要在 ajax 响应中更新的特定实体。

    2. 将您希望通过 ajax 更新的&lt;h:graphicImage/&gt;id 属性添加到您的&lt;a4j:ajax/&gt;render 列表中。将图像的值设置为动态表达式,以便您可以在支持 bean 中将其切换出来

       <a4j:ajax event="selectionchange" listener="#{myBean.rowListener}" render="indicatorImg"/>        
       <h:graphicImage id="indicatorImg" value="#{myBean.desiredImagePath}"/>
      
    3. 连接您的 ajax 侦听器以将所选实体的 id 添加到 ajaxKeys 集并根据需要修改 desiredImagePath 属性。

      public void rowListener(AjaxBehaviourEvent evt){
      //I assume you're already managing your selection properly
      //Change the value of the desiredImagePath here too.
       ajaxKeysSet.add(mySelection.getId()); //if you want to update multiple rows
              OR
       ajaxKeysSet = Collections.singleton(mySelection.getId()); //save a single id for ajax update
      }
      

    【讨论】:

      猜你喜欢
      • 2011-07-03
      • 1970-01-01
      • 2014-01-22
      • 1970-01-01
      • 2020-03-15
      • 1970-01-01
      • 1970-01-01
      • 2015-07-09
      • 1970-01-01
      相关资源
      最近更新 更多