使用flex和java,如何在实体具有关系(一对多或任何其他)时填充数据网格

时间:2022-04-26 20:24:10

I am using flex4 on the frontend, and java spring services on the backend. When I follow the tutorials, I can get entities from db (mysql5.0) and fill the datagrid provided by Flex on the client side. However, what the trouble is when my entity include a relation with another entity (I mean an Object) I cannot write even any string property of that object.

我在前端使用flex4,在后端使用java spring服务。当我按照教程,我可以从db(mysql5.0)获取实体并在客户端填充Flex提供的数据网格。但是,当我的实体包含与另一个实体的关系(我的意思是一个对象)时,我甚至无法编写该对象的任何字符串属性。

To clearify let me give an ex;

为了清楚,让我给出一个前任;

@Entity
@Table(name = "roleInfo")
public class RoleInfo implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = -8297592329833181352L; 

@Column(name = "username")
private String username;

@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy = "roleInfo")
private List<Role> roles; 

@Entity
public class Role ... {
    private String name;
    //accesor methods.. vs. vs..
..
}

Now, I would be glad to hear your solutions in order to print out the name of the Role object while I am listing datas of roleInfo entity.

现在,我很高兴听到您的解决方案,以便在列出roleInfo实体的数据时打印出Role对象的名称。

Moreover, here the flex side ex;

此外,这里是flex side ex;

    <mx:columns>
            <mx:DataGridColumn headerText="username" dataField="username"/>
            <mx:DataGridColumn headerText="name" dataField="roles.name"/> //Prob. is here, It didnt work:)
            ..
        </mx:columns>

1 个解决方案

#1


1  

You can use the labelFunction property of the DataGridColumn to achieve this. In there you can iterate over the roles list and generate a concatenated string and return the string.

您可以使用DataGridColumn的labelFunction属性来实现此目的。在那里,您可以遍历角色列表并生成连接字符串并返回字符串。

#1


1  

You can use the labelFunction property of the DataGridColumn to achieve this. In there you can iterate over the roles list and generate a concatenated string and return the string.

您可以使用DataGridColumn的labelFunction属性来实现此目的。在那里,您可以遍历角色列表并生成连接字符串并返回字符串。