Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Helping doing a summation in JSP / JSTL Code (also need a quick code review)  RSS feed

 
James Dekker
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am a complete newbie to JSP/JSTL/JSP EL...

Suppose I have the following Java code snippet that works correctly, as follows:



Was wondering how I could properly do this in JSP using JSTL (Standard JSTL with Struts) / JSP EL?

So far, I came up with:



Questions:

* How would one implement the summation (targetAccountLine.amount) just like I did in the correct working Java code?

* Is my attempt at converting the Java code into JSP / JSTL correct?

* How would I remove the other transactions, and just keep the first one, which now contains the total (please see how the working Java code snippet does it on line 12) in my JSP code snippet?

Thank you for taking the time to read this...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it correct? Well... did it work?

Your c:when "test" attribute is wrong, the number one (1) should not be in quotes--it's a number, not a string. If you wanted to sum it up you'd use c:set and the appropriate expression--but I don't really know why you'd want to do that in the presentation layer; why not just do it in Java, where it's trivial to unit test and validate?
 
James Dekker
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,

Thanks for the response!

Its a long story on why it was decided in the presentation layer.

Basically, it had to do with no validation or unit testing required for this functionality.

Could you give me a describe (in terms of code) how to do the summation (following the Java code snippet in the example, above)?

Would I need to use traditional JSP scriptlet or the JSTL forEach?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!