开发者

Using flex and java, how to fill a datagrid when entity has a relation(one-to-many or any other)

开发者 https://www.devze.com 2023-02-18 19:40 出处:网络
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.

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.

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.

Moreover, here the 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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消