[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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?
0
ldbkutty
Asked:
ldbkutty
  • 8
  • 6
1 Solution
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now