Menu

#79 Trans view doesn't work on collections with accessory getter

v4m1
closed
nobody
None
5
2014-08-18
2009-11-15
No

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

Discussion

  • Javier Paniza

    Javier Paniza - 2009-11-18

    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 {
    ...

    public Collection&lt;Month&gt; getMonths\(\) \{
        Collection&lt;Month&gt; result = new ArrayList&lt;Month&gt;\(\);
        result.add\(new Month\("ENERO", 31\)\);
        result.add\(new Month\("FEBRERO", 28\)\);
        result.add\(new Month\("MARZO", 31\)\);
        result.add\(new Month\("ABRIL", 30\)\);
        result.add\(new Month\("MAYO", 31\)\);
        result.add\(new Month\("JUNIO", 30\)\);
        result.add\(new Month\("JULIO", 31\)\);
        result.add\(new Month\("AGOSTO", 30\)\);
        result.add\(new Month\("SEPTIEMBRE", 30\)\);
        result.add\(new Month\("OCTUBRE", 31\)\);
        result.add\(new Month\("NOVIEMBRE", 30\)\);
        result.add\(new Month\("DICIEMBRE", 31\)\);
        return result;
    \}
    

    }

    I also added the Month transient class:
    public class Month {

    private String name;
    private int days;
    

    ...
    }

    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");
    }

     
  • Javier Paniza

    Javier Paniza - 2009-11-18
    • milestone: --> v4m1
    • status: open --> closed
     

Log in to post a comment.