Hello,
I have the following collection definition (this is the only one in view):
@NoModify @NewAction("") @EditAction("") @RemoveSelectedAction("") @ListProperties("entityId, agreementId.customerId.shortName, startDate, endDate, state") @SuppressWarnings("unchecked") @AsEmbedded public Collection getCampaignsFinishingToday() { LOGGER.info("getCampaignsFinishingToday enter");
Query query = XPersistence.getManager().createNativeQuery(
"select * from campaign where endDate <= :today " + " order by endDate desc",
Campaign.class);
Calendar oCurrentCalendar = Calendar.getInstance();
oCurrentCalendar.setTime(Calendar.getInstance().getTime());
oCurrentCalendar.set(Calendar.HOUR_OF_DAY, oCurrentCalendar
.getMaximum(Calendar.HOUR_OF_DAY));
oCurrentCalendar.set(Calendar.MINUTE, oCurrentCalendar.getMaximum(Calendar.MINUTE));
oCurrentCalendar.set(Calendar.SECOND, oCurrentCalendar.getMaximum(Calendar.SECOND));
Date oCurrentDate = oCurrentCalendar.getTime();
LOGGER.info("current date: " + CommonSettigns.DATETIME_FORMAT.format(oCurrentDate));
query.setParameter("today", CommonSettigns.DATETIME_FORMAT.format(oCurrentDate));
LOGGER.info("getCampaignsFinishingToday exit");
return query.getResultList();
}
it doesn't receive any data from DB; in calculatedCollectionList.jsp
subview.getCollectionValues();
resturns empty collection because keyValues were not received... which is strange.. when I use standard collection it works correct.
Here is the potential solution for: View.getCollectionValues() throws XavaException method:
public List getCollectionValues() throws XavaException
{
assertRepresentsCollection("getCollectionValues()");
if (isCollectionCalculated() || !isDefaultListActionsForCollectionsIncluded())
{
// If calculated we obtain the data directly from the model object
Map mapMembersNames = new HashMap();
mapMembersNames.put(getMemberName(), new HashMap(getCollectionMemberNames()));
try
{
Map mapReturnValues = null;
Map<?, ?> mapKeys = getParent().getKeyValues();
if ((null != mapKeys) && (false == mapKeys.isEmpty()))
{
mapReturnValues = MapFacade.getValues(getParent().getModelName(), mapKeys,
mapMembersNames);
}
else
{
// get transient view object model so that it might be used instead of keyValues, what is more fill
// it with data so that accessory methods might be used on current view members values
Object oParentObject = getParent().getMetaModel().getPOJOClass().newInstance();
getParent().getMetaModel().fillPOJO(oParentObject, getParent().getValues());
mapReturnValues = MapFacade.getValues(getParent().getModelName(),
oParentObject,
mapMembersNames);
}
return (List) mapReturnValues.get(getMemberName());
}
catch (ObjectNotFoundException ex)
{ // New one is creating
return Collections.EMPTY_LIST;
}
catch (Exception ex)
{
log.error(ex.getMessage(), ex);
getErrors().add("collection_error", getMemberName());
throw new XavaException("collection_error", getMemberName());
}
}
else
{
// If not calculated we obtain the data from the Tab
return getCollectionValues(getCollectionTab().getAllKeys());
}
}
regards
Jacek
Jacek,
your fix works fine.
I'll include it in OX4m1.
To test your fix using OpenXavaTest I have added the "month" collection to the already existing Year transient class:
// Not entity
public class Year {
...
}
I also added the Month transient class:
public class Month {
...
}
And I created a new test class named ChangeActiveYearTest with the next method:
public void testCalculatedCollectionInATransientClass() throws Exception {
assertCollectionRowCount("months", 12);
assertValueInCollection("months", 0, 0, "ENERO");
assertValueInCollection("months", 0, 1, "31");
assertValueInCollection("months", 1, 0, "FEBRERO");
assertValueInCollection("months", 1, 1, "28");
}