This discussion is archived
8 Replies Latest reply: Dec 12, 2012 7:01 AM by 976745 RSS

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

976745 Newbie
Currently Being Moderated
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.

Thanks,
Karim

Edited by: 973742 on Dec 3, 2012 8:42 AM
  • 1. Re: stored value from data control doesn't display until next run
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Try to ppr the outputText components.
     // AdfFacesContext AdfFacesContext adfFacesCtx = AdfFacesContext.getCurrentInstance();
    
    // PPR adfFacesCtx.addPartialTarget(input);
    Input is the component you want to refresh.

    Timo
  • 2. Re: stored value from data control doesn't display until next run
    976745 Newbie
    Currently Being Moderated
    Hi Timo,

    Thanks for your help.

    I'm not sure I understand though.
    Are you suggesting I would add the below code to the data control class?
    How would I reference the JSF page outputText components?

    Karim
  • 3. Re: stored value from data control doesn't display until next run
    Timo Hahn Oracle ACE
    Currently Being Moderated
    No, you don't add this in your DC class. You add this to a listener in bean where you get the update data.

    Timo
  • 4. Re: stored value from data control doesn't display until next run
    976745 Newbie
    Currently Being Moderated
    Thanks Timo for that clarification

    Unfortunately I'm not very experienced with javabeans so I don't really know how to move forward with that.

    EDIT: I tried adding my DC class to the faces-config file as a Session bean and then changed the value for my outputText field to reference the variable within the created Bean.
    But I couldn't figure out how to force the update.  The only listener option I see in the outputText field is the attributeChangeListener which didn't work for this purpose.

    In a previous situation I was able to calculate a value in my DC class, store it in a private member variable and then retrieve the stored value in my JSF page using the following approach: "#{bindings.exampleVariable.inputValue}".
    So I'm not sure why that doesn't work in this case.

    Karim

    Edited by: 973742 on 05-Dec-2012 10:13
  • 5. Re: stored value from data control doesn't display until next run
    Jobinesh Pro
    Currently Being Moderated
    During rendering of the page, if the UI component bound to avgXXX are retrieved/evaluated before rendering the component which is bound to getData(), you may hit this issue. Can't you move the logic for getData() to an 'initilaization' method which would executed as part of DC or Bean initialization.
  • 6. Re: stored value from data control doesn't display until next run
    976745 Newbie
    Currently Being Moderated
    Thanks for your feedback Jobinesh

    I'm not sure I can move the getData() method to the constructor though, if that's what you mean by 'initialisation' method.

    Let me provide some details about the JSF page to clarify.

    There are several components on page (a bar graph, an area graph, some ADF tables, etc) - like a dashboard.
    Each component is contained within a PanelBox and is bound to a separate data control (one for each component) and the methods in each data control require one parameter - the value(s) selected by the user from a Select Many Choice dropdown list.

    This value identifies the building(s) the user is interested in retrieving the details for.
    Each data control then calls a backend method to query the required data with the selected building(s) included in the list of criteria.

    In other words, the data in the components (graphs, tables, outputText fields) needs to change each time the user selection changes in the Select Many dropdown list.

    Right now, every other component does update when the user selection changes except for these specific outputText fields.

    In fact I've just added a new component of outputText fields laid out in an HTML table (inside a PanelBox) and bound to another data control, and somehow these fields do update when the user selection changes.
    I don't understand why it works for this new component but not the original one.

    The only difference I can see between the two is that the original component consists of a PanelFormLayout with 4 PanelLabelAndMessage fields (containing the outputText fields in question) and directly below the PanelFormLayout (inside the same PanelBox) is an ADF table.
    The table is bound to the return list from the getData method of the data control and the 4 outputText fields are bound to the 4 private member variables in the data control.

    Thoroughly confused that this works for one case and not the other, especially since I don't really see how the two scenarios are materially different.

    Any further thoughts/comments/suggestions would be greatly appreciated.

    Thanks.
  • 7. Re: stored value from data control doesn't display until next run
    Jobinesh Pro
    Currently Being Moderated
    Thanks for the details.
    Can you try keeping Refresh="prepareModel" for the iterator(under executable section of pagedef) that is bound to the getData() method. Also make sure outputText fields are set as partialTarget for the selecteMany comp (you can also try explicit setting clientComponent="true" four outputText, though theoretically its not required when you have partial target set).
  • 8. Re: stored value from data control doesn't display until next run
    976745 Newbie
    Currently Being Moderated
    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 looked back at an earlier suggestion and 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

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points