how to use more than one viewobject in my action class

I have:

----------------------------------------------------------------------------------------------------------------------------------------------
PlanungView[] planungViews = null;

for (int curYear = calFrom.get(Calendar.YEAR); curYear <= calTo.get(Calendar.YEAR); curYear++) {
    calCurrent.set(Calendar.YEAR, curYear);
    calCurrent.set(Calendar.MONTH, 0);
    calCurrent.set(Calendar.DATE, 1);
    curDate = calCurrent.getTime();
    planungViews = planungsSession.getSumCapacity(levelOfTimeView, Integer.parseInt(filterReportForm.getViewType()), Integer.parseInt(filterReportForm.getAbteilungId()), curDate, filterReportForm.getMitarbeiterIds(), filterReportForm.getKundeIds(), filterReportForm.getProjektIds(), filterReportForm.getAufgabeIds());
}

for (int j = 0; j < planungViews.length; j++) {
  sumCapacity = sumCapacity + planungViews[j].getPlanValue().floatValue();
}
request.setAttribute("sumCapacityCustomers", String.valueOf(sumCapacity));

----------------------------------------------------------------------------------------------------------------------------------------------

My PlanungView carries all the information i need.

But, as expected if my for first loop runs for 5 or 6 (more than 1 time, to be precise), i am getting only the last PlanungView detail.

But i need to "have" all the PlanungView. (i.e., for example: 4 PlanungViews if my loop runs 4 times)

I first thought of storing each PlanungView in an arraylist ( like: arrayListPlanungViews.add(planungViews); ) in my first for loop. but that creates me problem when i try to display the "sumCapacityCustomers" attribute in my JSP.

So, whats the best scenario to do it?
LVL 32
ldbkuttyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Why not do

sumCapacity += planungsSession.getSumCapacity(...............................................)

?
0
CEHJCommented:
Or rather nest the second loop in the first?
0
ldbkuttyAuthor Commented:
Because i just need the "planValue" property of the PlanungView, i.e:

sumCapacity = sumCapacity + planungViews[j].getPlanValue().floatValue();

and store it.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

CEHJCommented:
PlanungView[] planungViews = null;
double sumCapacity = 0.0;

for (int curYear = calFrom.get(Calendar.YEAR); curYear <= calTo.get(Calendar.YEAR); curYear++) {
      calCurrent.set(Calendar.YEAR, curYear);
      calCurrent.set(Calendar.MONTH, 0);
      calCurrent.set(Calendar.DATE, 1);
      curDate = calCurrent.getTime();
      planungViews = planungsSession.getSumCapacity(levelOfTimeView, Integer.parseInt(filterReportForm.getViewType()), Integer.parseInt(filterReportForm.getAbteilungId()), curDate, filterReportForm.getMitarbeiterIds(), filterReportForm.getKundeIds(), filterReportForm.getProjektIds(), filterReportForm.getAufgabeIds());
      for (int j = 0; j < planungViews.length; j++) {
            sumCapacity += planungViews[j].getPlanValue().floatValue();
      }

      
}

request.setAttribute("sumCapacityCustomers", String.valueOf(sumCapacity));
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ldbkuttyAuthor Commented:
but i need two different "sumCapacity" if the first for loop runs for two times. the code you gave me adds up both, right?
0
CEHJCommented:
>>the code you gave me adds up both, right?

Yes, it adds up all. If you don't want that, reinitialize sumCapacity to 0.0 in the outer loop
0
CEHJCommented:
>>but i need two different "sumCapacity" if the first for loop runs for two times

And of course your previous code only saves *one* value into the request. Surely if you can have more than one, you need to save a list of sumCapacity?
0
ldbkuttyAuthor Commented:
"planungViews" contains the "planValue" property.

I'll try to explain more:

1. Say My first for loop runs two times. (year - 2004 and 2005)
2. For year - 2004, my getSumCapacity(...) Session EJB Method sets the "PlanungValue" and returns "PlanungViews".
PS: Not just one PlanungView but many. (Array - PlanungViews[]).
3. Now, i want to sum up all the PlanungView's getPlanValue() and return it.
4. Same procedure for year 2005.

If i have just one loop (i.e. either only 2004 or 2005) it works fine. If it runs two times like the example above, my existin code returns only the last (i.e. year - 2005) details.

Got it?
0
ldbkuttyAuthor Commented:
Would this be OK, then ?

PlanungView[] planungViews = null;
double sumCapacity = 0.0;
int counter = 0;

for (int curYear = calFrom.get(Calendar.YEAR); curYear <= calTo.get(Calendar.YEAR); curYear++) {
     sumCapacity = 0.0;
     calCurrent.set(Calendar.YEAR, curYear);
     calCurrent.set(Calendar.MONTH, 0);
     calCurrent.set(Calendar.DATE, 1);
     curDate = calCurrent.getTime();
     planungViews = planungsSession.getSumCapacity(levelOfTimeView, Integer.parseInt(filterReportForm.getViewType()), Integer.parseInt(filterReportForm.getAbteilungId()), curDate, filterReportForm.getMitarbeiterIds(), filterReportForm.getKundeIds(), filterReportForm.getProjektIds(), filterReportForm.getAufgabeIds());
     for (int j = 0; j < planungViews.length; j++) {
          sumCapacity += planungViews[j].getPlanValue().floatValue();
     }
     request.setAttribute("sumCapacityCustomers"+counter, String.valueOf(sumCapacity));
     counter++;
}

If yes, then could you tell me how i can display it in my JSP?
PS: I'll try and come back to you,

thanks for your idea.
0
CEHJCommented:
That's clear but not about where you want to use sumCapacity. If you want to store it in the request (to refer to your example) for each of the two years, then the setAttribute should be moved into the outer loop.
0
CEHJCommented:
Of course my last was written before seeing *your* last. Since they correspond, i assume i was right in my assumption.

>>If yes, then could you tell me how i can display it in my JSP?

Difficult to say without knowing the context of your posted code. Naturally if this were already in the jsp, you could do

out.println(sumCapacity)

where, at the moment, you're saving it in the request
0
ldbkuttyAuthor Commented:
that worked,,,,thanks..

:)
0
CEHJCommented:
8-)
0
ldbkuttyAuthor Commented:
CEHJ,

can you please help in implementin this:
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21203210.html

I have, fromDate : "10.09.2001" and toDate : "28.02.2002". I want to:
display every day, month and year between them.
i.e. : 10.09.2001
        11.09.2001
        12.09.2001
        ....
        ....
        31.12.2001
        01.01.2002
        02.01.2002
        ....
        28.02.2002

you can see i made the loop for year as:
for (int curYear = calFrom.get(Calendar.YEAR); curYear <= calTo.get(Calendar.YEAR); curYear++) {

but i really appreciate your help. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.