Search code examples
javajdeveloperoracle-adf

Java ADF stored value from data control doesn't display until next run


Basically I've got a JSF page with a number of components, including an ADF table populated with a List of data returned from a getData() method in my data control class. Above the table I'm trying to display some calculated values from the data displayed - but the field values are not being displayed correctly.

(I'm using JDev 11.1.1.5)

The data control class is called RecentDeals and the getData() method returns a List of Deal objects that includes a number of fields (dates, values, names, etc).

The RecentDeals class also contains private variables to store the calculated (average) values to be displayed above the table (eg. avgSize, avgTerm, avgRent, etc). In the same getData() method, after iterating through the List of Deals to perform required calculations (and storing the respective values along the way), the variables are updated with the calculated averages before returning the List of Deal objects that populates the table.

Below is an excerpt of the code for reference:

public class RecentDealsDC {

    private Double avgSize;
    private Double avgTerm;
    private Double avgRent;
    ...

    public RecentDealsDC() {
        super();
        avgSize = 0.0;
        avgTerm = 0.0;
        avgRent = 0.0;
        ...
    }

    public List<DealDTO> getData(List<String> businessUnits){
        List<TransactionDTO> transactions = new ArrayList<TransactionDTO>();
        List<DealDTO> deals = new ArrayList<DealDTO>();
        TransactionSessionBean transBean = lookupTransactionSessionBean();

        Double size = 0.0;
        Double term = 0.0;
        Double totalBaseRent = 0.0;
        ...
        Integer recordCount = 0;

        if (businessUnits != null && !businessUnits.isEmpty()){
            transactions = transBean.getDealsData(SystemUtil.getCurrentUser(), businessUnits);

            recordCount = transactions.size();

            if( recordCount > 0 ){
                for (int i=0; i < recordCount; i++){
                    TransactionDTO transObj = new TransactionDTO();
                    DealDTO dealObj = new DealDTO();

                    transObj = transactions.get(i);

                    // process transaction, execute logic, store deal values

                    size = size + transObj.getRentableArea();
                    term = term + transObj.getLeaseTerm();
                    totalBaseRent = totalBaseRent + (transObj.getRentableArea() * transObj.getBaseRent());
                    ...

                    deals.add(dealObj);
                }
            }

            avgSize = size / recordCount;
            avgTerm = term / recordCount;
            avgRent = totalBaseRent / size;
            ...

        }

        return deals;
    }
}

When I run my JSF page it correctly displays the data from the List of Deal objects but the calculated fields just display zero. When the user selects the next "criteria" to populate the table (from a dropdown list in the header), the calculated fields are then updated with the previous stored values. So in other words the header fields are showing the averages pertaining to the previous set of data and the cycle seems to continue for each subsequent user selection - so the user is forced to select another value to get the averages needed, which is obviously not acceptable.

I have confirmed in debug mode that the calculations are being executed correctly and the correct values are stored in the private variables before the List is returned.

Not sure what I'm missing here but I'm thinking I need to somehow "refresh" the outputText components to display the expected values right away. That is what I'm researching but at something of a loss right now.

Any suggestions/direction/ideas would be really appreciated.

EDIT: It looks like the outputText fields also update when I collapse and re-expand the panelBox they are contained inside. So I'm wondering if there's some way for me to manually perform that same update...

Thanks, Karim


Solution

  • The solution I came to is as follows:

    Revised the DC class getData method to return a new DTO that contained the original List resultset and the 4 variables I needed to display. Then I bound the resultset and variables from below the returned DTO to the same respective components (resultset in ADF table, variables in 4 outputText fields in header above resultset table). Then I added a Refresh="IfNeeded" property to the Iterator for the attribute bindings.

    Now my outputText fields refresh as expected at the same time as the resultSet changes!

    Karim