简体   繁体   English

JSF 数据表,包含来自两个不同来源的数据

[英]JSF datatable with data from two different sources

I currently have a table displayed on one of my jsf pages, bound to a backing bean accounts, which unsuprisingly is a list of accounts in the system.我目前在我的一个 jsf 页面上显示了一个表格,绑定到一个支持 bean 帐户,不出所料,这是系统中的帐户列表。 The table loops over all accounts displaying relevant data.该表循环显示所有显示相关数据的帐户。

Now I have the situation whereby I want to display some additional data on each row.现在我有一种情况,我想在每一行上显示一些额外的数据。 I also want to display some performance data associated with each account.我还想显示与每个帐户相关的一些性能数据。 The account class itself does not contain any members relating to the performance data. class 账户本身不包含任何与业绩数据相关的成员。

So - how can I display this data in the same table that comes from two separate sources?那么 - 我如何在来自两个不同来源的同一个表中显示这些数据? If I could somehow pass as a parameter the var of the current account in the datatable loop then I could use it to lookup the performance data for the client in a map, for example.例如,如果我能以某种方式在数据表循环中将当前帐户的 var 作为参数传递,那么我可以使用它在 map 中查找客户端的性能数据。 I don't know how I could do that though.我不知道我怎么能做到这一点。

All suggestions are much appreicated!非常感谢所有建议!

To do things like this I usually implement 'relationship' methods in my model objects that retrieve related objects.为了做这样的事情,我通常在检索相关对象的 model 对象中实现“关系”方法。 For example:例如:

public class Account {
    ...
    public Client getClient() {
        // Retrieve the relevant client.
        // This could hit the database the first time it is called and then retrieve the in-memory object on successive calls.
        // Alternatively a previously instantiated Client may have been set for this Account.
    }
    ...
}

public class Client() {
    ...
    public String getName() {
        return (name);
    }
    ...
}

Then you can just do this in your JSF:然后您可以在 JSF 中执行此操作:

<h:outputText id="clientName" value="account.client.name" />

In the end I decided it was best to create a new class which contained both the account and performance data as members.最后,我决定最好创建一个新的 class,其中包含作为成员的帐户和绩效数据。

However, I did also discover a way in which you can communicate back the current row of your table.但是,我确实还发现了一种可以将表的当前行传回的方法。 My adding an HtmlDataTable to your class, you can set the DataTable in your jsf to bind to this.我将 HtmlDataTable 添加到您的 class 中,您可以将 jsf 中的 DataTable 设置为绑定到此。 Using the getRowData() of the HtmlDataTable you can get the object which represents the current row being iterated over.使用 HtmlDataTable 的 getRowData() 您可以获得 object ,它表示正在迭代的当前行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM