【问题标题】:Richfaces ExtendedDataTable selection questionRichfaces ExtendedDataTable 选择题
【发布时间】:2011-07-23 23:23:52
【问题描述】:

请帮忙。 看看http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=extendedDataTable&sample=exTableSelection&skin=blueSky

您会看到漂亮的“汽车市场”表格,支持多项选择。您还会注意到其中一个选定的行以粗体显示。这条粗线到底意味着什么?它是通过org.richfaces.component.UIExtendedDataTable 或任何其他RF 类的方法以某种方式管理的吗?找不到该行的 API。

我正在尝试做的是在支持 bean 中创建新项目并强制表选择指向新创建的项目。我已经设法通过setSelection() 设置选择,但我无法控制那条粗线,它仍然在原来的位置,请帮忙。

【问题讨论】:

    标签: jsf jsf-2 richfaces


    【解决方案1】:

    所选行的粗体样式由 Richfaces 附带的样式表管理。richfaces 中的每个主题都有自己的样式表。您可以参考official documentation ( It is still a draft version) 了解哪些样式类可用于自定义rich:extendedDataTable 的外观。

    例如rf-edt-r-selrf-edt-r-act定义了选中行的样式,你可以通过在你使用rich:extendedDataTable的页面中为这些样式类名声明一个样式来覆盖它们

    <style type="text/css">
    .rf-edt-r-sel{
         background-color: yellow;
    }
    
    .rf-edt-r-act{
       font-weight: bold;    
       color: red;
    }   
    </style>
    

    回复评论:

    RowKey 似乎是扩展表的行号。如果要从 UIExtendedDataTable 获取底层对象(即 InventoryItem ),则必须在调用 getRowData() 之前使用 setRowKey(selectionKey) 设置要检索的行号以获取实际对象。因此dataTable.setRowKey(selectionKey) 用于从UIExtendedDataTable 中获取选定的InventoryItem,以便将它们放入selectionItems(将显示在扩展表旁边的“选定行”框中)。对于Object originalKey = dataTable.getRowKey();dataTable.setRowKey(originalKey);,您可以参考此link

    在richfaces 3.3 中,我发现UIExtendedDataTable 有一个名为setActiveRowKey() 的方法,似乎可以设置活动记录。但是在最新版本的richfaces 4.0 CR1中被删除了。所以也许你可以使用UIExtendedDataTable's java script API来达到同样的效果。

    首先在 MBean 中定义一个名为 boldRowint 属性。然后您将有一个&lt;a4j:commandButton&gt; 来调用 Mbean 的方法。此方法将根据您的逻辑分配您要选择的行号。按钮的oncomplete 属性应该调用UIExtendedDataTable 的JavaScript API 来选择行号等于boldRow 的行,然后使用render 属性刷新UIExtendedDataTable。所以&lt;a4j:commandButton&gt;&lt;rich:extendedDataTable&gt; 应该是这样的:

     <a4j:commandButton value="Submit" action = "#{MBean.action}" render="#{rich:clientId('table')}"  
               oncomplete="#{rich:component('table')}.selectRow(#{MBean.boldRow}); #{rich:component('table')}.setActiveRow(#{MBean.boldRow});" />
    
    <rich:extendedDataTable id="table" .....
    ................
    </rich:extendedDataTable>
    

    【讨论】:

    • 感谢链接,但我仍然不明白docs.jboss.org/richfaces/latest_4_0_X/Component_Reference/en-US/… 中的代码,方法public void selectionListener()。有一行“dataTable.setRowKey(selectionKey)”,始终由“dataTable.setRowKey(originalKey)”跟随和重写。这是为什么?负责粗线的是rowKey吗?我需要并通过 API 控制大胆的选择。
    猜你喜欢
    • 1970-01-01
    • 2011-12-25
    • 2015-02-07
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 2016-04-02
    相关资源
    最近更新 更多