Link to home
Start Free TrialLog in
Avatar of ldbkutty
ldbkuttyFlag for India

asked on

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Why not do

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

?
Or rather nest the second loop in the first?
Avatar of ldbkutty

ASKER

Because i just need the "planValue" property of the PlanungView, i.e:

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

and store it.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
but i need two different "sumCapacity" if the first for loop runs for two times. the code you gave me adds up both, right?
>>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
>>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?
"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?
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.
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.
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
that worked,,,,thanks..

:)
8-)
CEHJ,

can you please help in implementin this:
https://www.experts-exchange.com/questions/21203210/calendar-date-question.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. :)