| Author |
Struts 1 - Doing math on the value of a struts bean
|
Jonathan Jekeli
Greenhorn
Joined: Jul 27, 2011
Posts: 4
|
|
I feel like this should be fairly simple... I apologize if this is a stupid question but I'm fairly new to jsp and struts. I am retrieving a property that for storage purposes needs to be in Kb, however I would like to display in in Mb, necessitating dividing by 1000.
As you can see, the value is getting written in to a table. How can i take this bean and simply divide the value by 1000?
Thanks!
|
 |
Shankar Tanikella
Ranch Hand
Joined: Jan 30, 2011
Posts: 329
|
|
Unfortunately, may be it is not possible (unless if you use scriptlets). To me, the best way to do is to calculate it in the getter method of your form bean if it is always required in MBs
|
Have Fun with Java
little,little.. little by little makes a lot..
|
 |
Jonathan Jekeli
Greenhorn
Joined: Jul 27, 2011
Posts: 4
|
|
|
Unfortunately it is not always required in Mb. You mentioned that it may be possible using scriptlets. I figured this was the case, how would I used scriptlets to do this?
|
 |
Shankar Tanikella
Ranch Hand
Joined: Jan 30, 2011
Posts: 329
|
|
Though I don't feel good sharing scriptlet code which is not advised,....here it goes (I hope someone else could help in this)
I didn't try it personally, try something like below. This should serve the purpose for now
|
 |
Jonathan Jekeli
Greenhorn
Joined: Jul 27, 2011
Posts: 4
|
|
|
I know scriptlets are generally a bad habit to get into, b/c you don't want to implement business logic in presentation components, but this is perfect for this one need. Thank you, works perfectly.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56230
|
|
|
Why aren't you handling this in the bean instead of polluting the JSP?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Jonathan Jekeli
Greenhorn
Joined: Jul 27, 2011
Posts: 4
|
|
|
Just the simple conversion didn't seem worth adding another property, since is the only place it will be used in MB (more user-friendly for viewing purposes). However for storage purposes it is better to be in kB for better granularity
|
 |
 |
|
|
subject: Struts 1 - Doing math on the value of a struts bean
|
|
|