|
View:
New views
13 Messages
—
Rating Filter:
Alert me
|
|
|
adding values to a variable inside iterator tagHi,
I have a simple iterator tag like the following <s:iterator value="results"> <s:property value="value1"/> </s:iterator> is there a way to get the total of value1 at the end of this iterator tag? basically in java we would do totalValue += value1; and then at the end of the loop we would have total of value1. Is that possible to do with an iterator tag? |
|
|
Re: adding values to a variable inside iterator tagYou're far better off doing it inside the Action class.
That said, you can probably use s:set to get what you want. jk On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma <bhaarat.s@...>wrote: > Hi, > I have a simple iterator tag like the following > > <s:iterator value="results"> > > <s:property value="value1"/> > > </s:iterator> > > is there a way to get the total of value1 at the end of this iterator tag? > > basically in java we would do totalValue += value1; and then at the end of > the loop we would have total of value1. > > Is that possible to do with an iterator tag? > -- Jim Kiley Senior Technical Consultant | Summa [p] 412.258.3346 http://www.summa-tech.com |
|
|
Re: adding values to a variable inside iterator tagfor our purpose i'd prefer doing it in the iterator tag.
I tried something like this <s:set name="calcTotalDebtAmt" value="%{calcTotalDebtAmt+=totalDebtAmt}"/> but this does not seem to work. what can fix this? On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley <jhkiley@...> wrote: > You're far better off doing it inside the Action class. > That said, you can probably use s:set to get what you want. > > jk > > On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma <bhaarat.s@... > >wrote: > > > Hi, > > I have a simple iterator tag like the following > > > > <s:iterator value="results"> > > > > <s:property value="value1"/> > > > > </s:iterator> > > > > is there a way to get the total of value1 at the end of this iterator > tag? > > > > basically in java we would do totalValue += value1; and then at the end > of > > the loop we would have total of value1. > > > > Is that possible to do with an iterator tag? > > > > > > -- > Jim Kiley > Senior Technical Consultant | Summa > [p] 412.258.3346 > http://www.summa-tech.com > |
|
|
Re: adding values to a variable inside iterator tagDoes anyone know how to calculate the total value by making use of the
<s:set> tag? On Mon, Jun 29, 2009 at 1:16 PM, Bhaarat Sharma <bhaarat.s@...> wrote: > for our purpose i'd prefer doing it in the iterator tag. > I tried something like this > > <s:set name="calcTotalDebtAmt" value="%{calcTotalDebtAmt+=totalDebtAmt}"/> > > but this does not seem to work. > > what can fix this? > > > On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley <jhkiley@...>wrote: > >> You're far better off doing it inside the Action class. >> That said, you can probably use s:set to get what you want. >> >> jk >> >> On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma <bhaarat.s@... >> >wrote: >> >> > Hi, >> > I have a simple iterator tag like the following >> > >> > <s:iterator value="results"> >> > >> > <s:property value="value1"/> >> > >> > </s:iterator> >> > >> > is there a way to get the total of value1 at the end of this iterator >> tag? >> > >> > basically in java we would do totalValue += value1; and then at the end >> of >> > the loop we would have total of value1. >> > >> > Is that possible to do with an iterator tag? >> > >> >> >> >> -- >> Jim Kiley >> Senior Technical Consultant | Summa >> [p] 412.258.3346 >> http://www.summa-tech.com >> > > |
|
|
Re: adding values to a variable inside iterator tagDoes it work if you replace the "+=" with a "+"?
jk On Wed, Jul 1, 2009 at 4:39 PM, Bhaarat Sharma <bhaarat.s@...> wrote: > Does anyone know how to calculate the total value by making use of the > <s:set> tag? > On Mon, Jun 29, 2009 at 1:16 PM, Bhaarat Sharma <bhaarat.s@...> > wrote: > > > for our purpose i'd prefer doing it in the iterator tag. > > I tried something like this > > > > <s:set name="calcTotalDebtAmt" > value="%{calcTotalDebtAmt+=totalDebtAmt}"/> > > > > but this does not seem to work. > > > > what can fix this? > > > > > > On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley <jhkiley@... > >wrote: > > > >> You're far better off doing it inside the Action class. > >> That said, you can probably use s:set to get what you want. > >> > >> jk > >> > >> On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma <bhaarat.s@... > >> >wrote: > >> > >> > Hi, > >> > I have a simple iterator tag like the following > >> > > >> > <s:iterator value="results"> > >> > > >> > <s:property value="value1"/> > >> > > >> > </s:iterator> > >> > > >> > is there a way to get the total of value1 at the end of this iterator > >> tag? > >> > > >> > basically in java we would do totalValue += value1; and then at the > end > >> of > >> > the loop we would have total of value1. > >> > > >> > Is that possible to do with an iterator tag? > >> > > >> > >> > >> > >> -- > >> Jim Kiley > >> Senior Technical Consultant | Summa > >> [p] 412.258.3346 > >> http://www.summa-tech.com > >> > > > > > -- Jim Kiley Senior Technical Consultant | Summa [p] 412.258.3346 http://www.summa-tech.com |
|
|
Re: adding values to a variable inside iterator tagno :(
I tried the following <s:iterator value="resultList" status="status"> <s:text name="number.format"><s:param value = "totalCount"/></s:text> <s:set name="calcTotalDebtAmt" value="%{calcTotalDebtAmt+totalCount}"/> </s:iterator> and tried to print it <s:property value="#calcTotalDebtAmt"/> but it shows nothing :( On Wed, Jul 1, 2009 at 4:41 PM, Jim Kiley <jhkiley@...> wrote: > Does it work if you replace the "+=" with a "+"? > jk > > On Wed, Jul 1, 2009 at 4:39 PM, Bhaarat Sharma <bhaarat.s@...> > wrote: > > > Does anyone know how to calculate the total value by making use of the > > <s:set> tag? > > On Mon, Jun 29, 2009 at 1:16 PM, Bhaarat Sharma <bhaarat.s@...> > > wrote: > > > > > for our purpose i'd prefer doing it in the iterator tag. > > > I tried something like this > > > > > > <s:set name="calcTotalDebtAmt" > > value="%{calcTotalDebtAmt+=totalDebtAmt}"/> > > > > > > but this does not seem to work. > > > > > > what can fix this? > > > > > > > > > On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley <jhkiley@... > > >wrote: > > > > > >> You're far better off doing it inside the Action class. > > >> That said, you can probably use s:set to get what you want. > > >> > > >> jk > > >> > > >> On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma <bhaarat.s@... > > >> >wrote: > > >> > > >> > Hi, > > >> > I have a simple iterator tag like the following > > >> > > > >> > <s:iterator value="results"> > > >> > > > >> > <s:property value="value1"/> > > >> > > > >> > </s:iterator> > > >> > > > >> > is there a way to get the total of value1 at the end of this > iterator > > >> tag? > > >> > > > >> > basically in java we would do totalValue += value1; and then at the > > end > > >> of > > >> > the loop we would have total of value1. > > >> > > > >> > Is that possible to do with an iterator tag? > > >> > > > >> > > >> > > >> > > >> -- > > >> Jim Kiley > > >> Senior Technical Consultant | Summa > > >> [p] 412.258.3346 > > >> http://www.summa-tech.com > > >> > > > > > > > > > > > > -- > Jim Kiley > Senior Technical Consultant | Summa > [p] 412.258.3346 > http://www.summa-tech.com > |
|
|
Re: adding values to a variable inside iterator tagoh nevermind.
was experimenting and <s:set name="calcTotalDebtAmt" value="%{#calcTotalDebtAmt+totalCount}"/> works! bless OGNL On Wed, Jul 1, 2009 at 4:55 PM, Bhaarat Sharma <bhaarat.s@...> wrote: > no :( > I tried the following > <s:iterator value="resultList" status="status"> > <s:text name="number.format"><s:param value = > "totalCount"/></s:text> > <s:set name="calcTotalDebtAmt" > value="%{calcTotalDebtAmt+totalCount}"/> > </s:iterator> > > and tried to print it > <s:property value="#calcTotalDebtAmt"/> > > but it shows nothing :( > > On Wed, Jul 1, 2009 at 4:41 PM, Jim Kiley <jhkiley@...> wrote: > >> Does it work if you replace the "+=" with a "+"? >> jk >> >> On Wed, Jul 1, 2009 at 4:39 PM, Bhaarat Sharma <bhaarat.s@...> >> wrote: >> >> > Does anyone know how to calculate the total value by making use of the >> > <s:set> tag? >> > On Mon, Jun 29, 2009 at 1:16 PM, Bhaarat Sharma <bhaarat.s@...> >> > wrote: >> > >> > > for our purpose i'd prefer doing it in the iterator tag. >> > > I tried something like this >> > > >> > > <s:set name="calcTotalDebtAmt" >> > value="%{calcTotalDebtAmt+=totalDebtAmt}"/> >> > > >> > > but this does not seem to work. >> > > >> > > what can fix this? >> > > >> > > >> > > On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley <jhkiley@... >> > >wrote: >> > > >> > >> You're far better off doing it inside the Action class. >> > >> That said, you can probably use s:set to get what you want. >> > >> >> > >> jk >> > >> >> > >> On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma < >> bhaarat.s@... >> > >> >wrote: >> > >> >> > >> > Hi, >> > >> > I have a simple iterator tag like the following >> > >> > >> > >> > <s:iterator value="results"> >> > >> > >> > >> > <s:property value="value1"/> >> > >> > >> > >> > </s:iterator> >> > >> > >> > >> > is there a way to get the total of value1 at the end of this >> iterator >> > >> tag? >> > >> > >> > >> > basically in java we would do totalValue += value1; and then at the >> > end >> > >> of >> > >> > the loop we would have total of value1. >> > >> > >> > >> > Is that possible to do with an iterator tag? >> > >> > >> > >> >> > >> >> > >> >> > >> -- >> > >> Jim Kiley >> > >> Senior Technical Consultant | Summa >> > >> [p] 412.258.3346 >> > >> http://www.summa-tech.com >> > >> >> > > >> > > >> > >> >> >> >> -- >> Jim Kiley >> Senior Technical Consultant | Summa >> [p] 412.258.3346 >> http://www.summa-tech.com >> > > |
|
|
Re: adding values to a variable inside iterator tagI don't know how Struts 2 tags work under the hood, but it's possible that
it's going out of scope because you declared it in the iterator, or it's silently throwing an error because it isn't initialized. Before your <s:iterator> starts, do <s:set name="calcTotalDebtAmt" value="0"/>. This could be handled inside your action class with like two lines of code, of course, and as a side benefit you could write meaningful unit tests to be sure you'd gotten it right. jk On Wed, Jul 1, 2009 at 4:55 PM, Bhaarat Sharma <bhaarat.s@...> wrote: > no :( > I tried the following > <s:iterator value="resultList" status="status"> > <s:text name="number.format"><s:param value = "totalCount"/></s:text> > <s:set name="calcTotalDebtAmt" > value="%{calcTotalDebtAmt+totalCount}"/> > </s:iterator> > > and tried to print it > <s:property value="#calcTotalDebtAmt"/> > > but it shows nothing :( > > On Wed, Jul 1, 2009 at 4:41 PM, Jim Kiley <jhkiley@...> wrote: > > > Does it work if you replace the "+=" with a "+"? > > jk > > > > On Wed, Jul 1, 2009 at 4:39 PM, Bhaarat Sharma <bhaarat.s@...> > > wrote: > > > > > Does anyone know how to calculate the total value by making use of the > > > <s:set> tag? > > > On Mon, Jun 29, 2009 at 1:16 PM, Bhaarat Sharma <bhaarat.s@...> > > > wrote: > > > > > > > for our purpose i'd prefer doing it in the iterator tag. > > > > I tried something like this > > > > > > > > <s:set name="calcTotalDebtAmt" > > > value="%{calcTotalDebtAmt+=totalDebtAmt}"/> > > > > > > > > but this does not seem to work. > > > > > > > > what can fix this? > > > > > > > > > > > > On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley <jhkiley@... > > > >wrote: > > > > > > > >> You're far better off doing it inside the Action class. > > > >> That said, you can probably use s:set to get what you want. > > > >> > > > >> jk > > > >> > > > >> On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma < > bhaarat.s@... > > > >> >wrote: > > > >> > > > >> > Hi, > > > >> > I have a simple iterator tag like the following > > > >> > > > > >> > <s:iterator value="results"> > > > >> > > > > >> > <s:property value="value1"/> > > > >> > > > > >> > </s:iterator> > > > >> > > > > >> > is there a way to get the total of value1 at the end of this > > iterator > > > >> tag? > > > >> > > > > >> > basically in java we would do totalValue += value1; and then at > the > > > end > > > >> of > > > >> > the loop we would have total of value1. > > > >> > > > > >> > Is that possible to do with an iterator tag? > > > >> > > > > >> > > > >> > > > >> > > > >> -- > > > >> Jim Kiley > > > >> Senior Technical Consultant | Summa > > > >> [p] 412.258.3346 > > > >> http://www.summa-tech.com > > > >> > > > > > > > > > > > > > > > > > > > -- > > Jim Kiley > > Senior Technical Consultant | Summa > > [p] 412.258.3346 > > http://www.summa-tech.com > > > -- Jim Kiley Senior Technical Consultant | Summa [p] 412.258.3346 http://www.summa-tech.com |
|
|
Re: adding values to a variable inside iterator tagbut if I do it in my action class then I am adding extra 'time'.
to begin with I anyways have to iterate over the list in my JSP. Just to calculate total if I iterate over the list again in java code then I am doing two iterations through the list. Just didnt seem very efficient for my need. Thanks for your suggestion!! :) On Wed, Jul 1, 2009 at 4:59 PM, Jim Kiley <jhkiley@...> wrote: > I don't know how Struts 2 tags work under the hood, but it's possible that > it's going out of scope because you declared it in the iterator, or it's > silently throwing an error because it isn't initialized. Before your > <s:iterator> starts, do <s:set name="calcTotalDebtAmt" value="0"/>. > This could be handled inside your action class with like two lines of code, > of course, and as a side benefit you could write meaningful unit tests to > be > sure you'd gotten it right. > > jk > > On Wed, Jul 1, 2009 at 4:55 PM, Bhaarat Sharma <bhaarat.s@...> > wrote: > > > no :( > > I tried the following > > <s:iterator value="resultList" status="status"> > > <s:text name="number.format"><s:param value = > "totalCount"/></s:text> > > <s:set name="calcTotalDebtAmt" > > value="%{calcTotalDebtAmt+totalCount}"/> > > </s:iterator> > > > > and tried to print it > > <s:property value="#calcTotalDebtAmt"/> > > > > but it shows nothing :( > > > > On Wed, Jul 1, 2009 at 4:41 PM, Jim Kiley <jhkiley@...> > wrote: > > > > > Does it work if you replace the "+=" with a "+"? > > > jk > > > > > > On Wed, Jul 1, 2009 at 4:39 PM, Bhaarat Sharma <bhaarat.s@...> > > > wrote: > > > > > > > Does anyone know how to calculate the total value by making use of > the > > > > <s:set> tag? > > > > On Mon, Jun 29, 2009 at 1:16 PM, Bhaarat Sharma <bhaarat.s@... > > > > > > wrote: > > > > > > > > > for our purpose i'd prefer doing it in the iterator tag. > > > > > I tried something like this > > > > > > > > > > <s:set name="calcTotalDebtAmt" > > > > value="%{calcTotalDebtAmt+=totalDebtAmt}"/> > > > > > > > > > > but this does not seem to work. > > > > > > > > > > what can fix this? > > > > > > > > > > > > > > > On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley < > jhkiley@... > > > > >wrote: > > > > > > > > > >> You're far better off doing it inside the Action class. > > > > >> That said, you can probably use s:set to get what you want. > > > > >> > > > > >> jk > > > > >> > > > > >> On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma < > > bhaarat.s@... > > > > >> >wrote: > > > > >> > > > > >> > Hi, > > > > >> > I have a simple iterator tag like the following > > > > >> > > > > > >> > <s:iterator value="results"> > > > > >> > > > > > >> > <s:property value="value1"/> > > > > >> > > > > > >> > </s:iterator> > > > > >> > > > > > >> > is there a way to get the total of value1 at the end of this > > > iterator > > > > >> tag? > > > > >> > > > > > >> > basically in java we would do totalValue += value1; and then at > > the > > > > end > > > > >> of > > > > >> > the loop we would have total of value1. > > > > >> > > > > > >> > Is that possible to do with an iterator tag? > > > > >> > > > > > >> > > > > >> > > > > >> > > > > >> -- > > > > >> Jim Kiley > > > > >> Senior Technical Consultant | Summa > > > > >> [p] 412.258.3346 > > > > >> http://www.summa-tech.com > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > Jim Kiley > > > Senior Technical Consultant | Summa > > > [p] 412.258.3346 > > > http://www.summa-tech.com > > > > > > > > > -- > Jim Kiley > Senior Technical Consultant | Summa > [p] 412.258.3346 > http://www.summa-tech.com > |
|
|
Re: adding values to a variable inside iterator tagI will bet one dollar that the amount of time it takes to calculate this
value inside your Action class is less than or equal to the time it takes it to calculate the value inside the iterator in your JSP. And it's a vanishingly small amount compared to network latency. Unless you're writing code that's going to be hammered at the requests-per-second scale, optimizing out a for loop is not the best use of your time as a developer. When you're doing initial development, optimize in favor of readability and testability. Once you're in or close to production, analyze to find bottlenecks. Finding the sum of a bunch of values is not going to be your bottleneck. jk On Wed, Jul 1, 2009 at 5:03 PM, Bhaarat Sharma <bhaarat.s@...> wrote: > but if I do it in my action class then I am adding extra 'time'. > to begin with I anyways have to iterate over the list in my JSP. Just to > calculate total if I iterate over the list again in java code then I am > doing two iterations through the list. Just didnt seem very efficient for > my need. > > Thanks for your suggestion!! :) > > > On Wed, Jul 1, 2009 at 4:59 PM, Jim Kiley <jhkiley@...> wrote: > > > I don't know how Struts 2 tags work under the hood, but it's possible > that > > it's going out of scope because you declared it in the iterator, or it's > > silently throwing an error because it isn't initialized. Before your > > <s:iterator> starts, do <s:set name="calcTotalDebtAmt" value="0"/>. > > This could be handled inside your action class with like two lines of > code, > > of course, and as a side benefit you could write meaningful unit tests to > > be > > sure you'd gotten it right. > > > > jk > > > > On Wed, Jul 1, 2009 at 4:55 PM, Bhaarat Sharma <bhaarat.s@...> > > wrote: > > > > > no :( > > > I tried the following > > > <s:iterator value="resultList" status="status"> > > > <s:text name="number.format"><s:param value = > > "totalCount"/></s:text> > > > <s:set name="calcTotalDebtAmt" > > > value="%{calcTotalDebtAmt+totalCount}"/> > > > </s:iterator> > > > > > > and tried to print it > > > <s:property value="#calcTotalDebtAmt"/> > > > > > > but it shows nothing :( > > > > > > On Wed, Jul 1, 2009 at 4:41 PM, Jim Kiley <jhkiley@...> > > wrote: > > > > > > > Does it work if you replace the "+=" with a "+"? > > > > jk > > > > > > > > On Wed, Jul 1, 2009 at 4:39 PM, Bhaarat Sharma <bhaarat.s@...> > > > > wrote: > > > > > > > > > Does anyone know how to calculate the total value by making use of > > the > > > > > <s:set> tag? > > > > > On Mon, Jun 29, 2009 at 1:16 PM, Bhaarat Sharma < > bhaarat.s@... > > > > > > > > wrote: > > > > > > > > > > > for our purpose i'd prefer doing it in the iterator tag. > > > > > > I tried something like this > > > > > > > > > > > > <s:set name="calcTotalDebtAmt" > > > > > value="%{calcTotalDebtAmt+=totalDebtAmt}"/> > > > > > > > > > > > > but this does not seem to work. > > > > > > > > > > > > what can fix this? > > > > > > > > > > > > > > > > > > On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley < > > jhkiley@... > > > > > >wrote: > > > > > > > > > > > >> You're far better off doing it inside the Action class. > > > > > >> That said, you can probably use s:set to get what you want. > > > > > >> > > > > > >> jk > > > > > >> > > > > > >> On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma < > > > bhaarat.s@... > > > > > >> >wrote: > > > > > >> > > > > > >> > Hi, > > > > > >> > I have a simple iterator tag like the following > > > > > >> > > > > > > >> > <s:iterator value="results"> > > > > > >> > > > > > > >> > <s:property value="value1"/> > > > > > >> > > > > > > >> > </s:iterator> > > > > > >> > > > > > > >> > is there a way to get the total of value1 at the end of this > > > > iterator > > > > > >> tag? > > > > > >> > > > > > > >> > basically in java we would do totalValue += value1; and then > at > > > the > > > > > end > > > > > >> of > > > > > >> > the loop we would have total of value1. > > > > > >> > > > > > > >> > Is that possible to do with an iterator tag? > > > > > >> > > > > > > >> > > > > > >> > > > > > >> > > > > > >> -- > > > > > >> Jim Kiley > > > > > >> Senior Technical Consultant | Summa > > > > > >> [p] 412.258.3346 > > > > > >> http://www.summa-tech.com > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > Jim Kiley > > > > Senior Technical Consultant | Summa > > > > [p] 412.258.3346 > > > > http://www.summa-tech.com > > > > > > > > > > > > > > > -- > > Jim Kiley > > Senior Technical Consultant | Summa > > [p] 412.258.3346 > > http://www.summa-tech.com > > > -- Jim Kiley Senior Technical Consultant | Summa [p] 412.258.3346 http://www.summa-tech.com |
|
|
Re: adding values to a variable inside iterator tagthanks for your advice.
"...optimizing out a for loop is not the best use of your time as a developer." I second that. But in this case why would I write another for loop to do something that can be done in the for loop that I already have? Unless there is an issue with doing this inside s:iterator tag, issues like code readability or amount of time, I thought it would be better to not write a method in my action class just for this. Furthermore, I got to learn something about ognl :) On Wed, Jul 1, 2009 at 5:08 PM, Jim Kiley <jhkiley@...> wrote: > I will bet one dollar that the amount of time it takes to calculate this > value inside your Action class is less than or equal to the time it takes > it > to calculate the value inside the iterator in your JSP. And it's a > vanishingly small amount compared to network latency. Unless you're > writing > code that's going to be hammered at the requests-per-second scale, > optimizing out a for loop is not the best use of your time as a developer. > > When you're doing initial development, optimize in favor of readability and > testability. Once you're in or close to production, analyze to find > bottlenecks. Finding the sum of a bunch of values is not going to be your > bottleneck. > > jk > > On Wed, Jul 1, 2009 at 5:03 PM, Bhaarat Sharma <bhaarat.s@...> > wrote: > > > but if I do it in my action class then I am adding extra 'time'. > > to begin with I anyways have to iterate over the list in my JSP. Just to > > calculate total if I iterate over the list again in java code then I am > > doing two iterations through the list. Just didnt seem very efficient > for > > my need. > > > > Thanks for your suggestion!! :) > > > > > > On Wed, Jul 1, 2009 at 4:59 PM, Jim Kiley <jhkiley@...> > wrote: > > > > > I don't know how Struts 2 tags work under the hood, but it's possible > > that > > > it's going out of scope because you declared it in the iterator, or > it's > > > silently throwing an error because it isn't initialized. Before your > > > <s:iterator> starts, do <s:set name="calcTotalDebtAmt" value="0"/>. > > > This could be handled inside your action class with like two lines of > > code, > > > of course, and as a side benefit you could write meaningful unit tests > to > > > be > > > sure you'd gotten it right. > > > > > > jk > > > > > > On Wed, Jul 1, 2009 at 4:55 PM, Bhaarat Sharma <bhaarat.s@...> > > > wrote: > > > > > > > no :( > > > > I tried the following > > > > <s:iterator value="resultList" status="status"> > > > > <s:text name="number.format"><s:param value = > > > "totalCount"/></s:text> > > > > <s:set name="calcTotalDebtAmt" > > > > value="%{calcTotalDebtAmt+totalCount}"/> > > > > </s:iterator> > > > > > > > > and tried to print it > > > > <s:property value="#calcTotalDebtAmt"/> > > > > > > > > but it shows nothing :( > > > > > > > > On Wed, Jul 1, 2009 at 4:41 PM, Jim Kiley <jhkiley@...> > > > wrote: > > > > > > > > > Does it work if you replace the "+=" with a "+"? > > > > > jk > > > > > > > > > > On Wed, Jul 1, 2009 at 4:39 PM, Bhaarat Sharma < > bhaarat.s@...> > > > > > wrote: > > > > > > > > > > > Does anyone know how to calculate the total value by making use > of > > > the > > > > > > <s:set> tag? > > > > > > On Mon, Jun 29, 2009 at 1:16 PM, Bhaarat Sharma < > > bhaarat.s@... > > > > > > > > > > wrote: > > > > > > > > > > > > > for our purpose i'd prefer doing it in the iterator tag. > > > > > > > I tried something like this > > > > > > > > > > > > > > <s:set name="calcTotalDebtAmt" > > > > > > value="%{calcTotalDebtAmt+=totalDebtAmt}"/> > > > > > > > > > > > > > > but this does not seem to work. > > > > > > > > > > > > > > what can fix this? > > > > > > > > > > > > > > > > > > > > > On Mon, Jun 29, 2009 at 12:08 PM, Jim Kiley < > > > jhkiley@... > > > > > > >wrote: > > > > > > > > > > > > > >> You're far better off doing it inside the Action class. > > > > > > >> That said, you can probably use s:set to get what you want. > > > > > > >> > > > > > > >> jk > > > > > > >> > > > > > > >> On Mon, Jun 29, 2009 at 12:03 PM, Bhaarat Sharma < > > > > bhaarat.s@... > > > > > > >> >wrote: > > > > > > >> > > > > > > >> > Hi, > > > > > > >> > I have a simple iterator tag like the following > > > > > > >> > > > > > > > >> > <s:iterator value="results"> > > > > > > >> > > > > > > > >> > <s:property value="value1"/> > > > > > > >> > > > > > > > >> > </s:iterator> > > > > > > >> > > > > > > > >> > is there a way to get the total of value1 at the end of this > > > > > iterator > > > > > > >> tag? > > > > > > >> > > > > > > > >> > basically in java we would do totalValue += value1; and then > > at > > > > the > > > > > > end > > > > > > >> of > > > > > > >> > the loop we would have total of value1. > > > > > > >> > > > > > > > >> > Is that possible to do with an iterator tag? > > > > > > >> > > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> -- > > > > > > >> Jim Kiley > > > > > > >> Senior Technical Consultant | Summa > > > > > > >> [p] 412.258.3346 > > > > > > >> http://www.summa-tech.com > > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > Jim Kiley > > > > > Senior Technical Consultant | Summa > > > > > [p] 412.258.3346 > > > > > http://www.summa-tech.com > > > > > > > > > > > > > > > > > > > > > -- > > > Jim Kiley > > > Senior Technical Consultant | Summa > > > [p] 412.258.3346 > > > http://www.summa-tech.com > > > > > > > > > -- > Jim Kiley > Senior Technical Consultant | Summa > [p] 412.258.3346 > http://www.summa-tech.com > |
|
|
Re: adding values to a variable inside iterator tagBhaarat Sharma wrote:
> But in this case why would I write another for loop to do > something that can be done in the for loop that I already have? Maybe learning about the life cycle of even a simple tag will convince you that doing unnecessary computation within the display layer is a mistake: http://java.sun.com/webservices/docs/1.6/api/javax/servlet/jsp/tagext/Tag.html Especially the more complex life cycles of more detailed tags (since s:set can have a body, it's got to implement BodyTag, I believe) : http://java.sun.com/webservices/docs/1.6/api/javax/servlet/jsp/tagext/IterationTag.html http://java.sun.com/webservices/docs/1.6/api/javax/servlet/jsp/tagext/BodyTag.html And since your summation actually did the work through OGNL, you also add the parsing/evaluation computational expense each time through that loop. -Dale --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: adding values to a variable inside iterator tagI think his point is that his view template is going to iterate these objects anyways, he just did not include the additional layout html for the resultsList. I don't think he was suggesting that getting a count by looping is better done in JSP tags rather than the action class. I am sure there is some form of branching logic that is also not shown otherwise he would just use resultsList.size.
|
| Free embeddable forum powered by Nabble | Forum Help |