0

如何使用 openxava 访问位于另一个实体的一个部分内的集合实体的详细信息元素?例如,在实体 A 的视图中,我们有 {S1,S2,S3} 部分,而在 S3 部分视图中,我们有 {实体 B 的集合}。现在我想访问实体 B 的详细信息元素,以便我可以在动作控制器中填充该元素。我怎么做?

4

3 回答 3

1

直接从视图中获取集合,方式如下:

Collection myCollection = getView().getSubview("myCollection").getCollectionObjects();

即使使用最旧的 OpenXava 版本,它也必须工作

于 2013-01-07T12:23:40.790 回答
0

You can do it in several ways. Here you have one, I have used it with some references that I want to modify from inside of an action called by the base module (which should work with your collection):

Query q = XPersistence.getManager().createQuery("JPQL QUERY TO RETRIVE THE COLLECTION WITH :parameterIfNeeded");
q.setParameter("parameterIfNeeded", "value");
List entityBList = q.getResultList();
if (getView().getModelName().equalsIgnoreCase("yourBaseModelViewName")) {
    getView().getSubview("yourSubViewName").setModel(entityBList);
    getView().getSubview("yourSubViewName").refresh();
}

You must to be using OX 4.6 to be able to use setModel(). And remember that the "yourSubViewName" is the name of the property for your collection into the base model.

I have not tested that code with a collection, so make the adjustments according to your needs, maybe you will need to CAST the query result list or something.

于 2013-01-03T20:39:00.307 回答
0

获取与视图关联的实体并从中获取集合。从 OpenXava 4.3 开始,您可以这样做:

MyEntity myEntity = (MyEntity) getView().getEntity();   
Collection myCollection = myEntity.getMyCollection();

如果您使用的是 4.3 之前的 OX,请按以下方式进行:

Map keyValues = getView().getKeyValuesWithValue();
if (!keyValues.isEmpty()) {
    MyEntity myEntity = (MyEntity) 
        MapFacade.findEntity(getView().getModelName(), keyValues);
    Collection myCollection = myEntity.getMyCollection();
}
于 2013-01-07T12:30:25.367 回答