• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 1 - Doing math on the value of a struts bean

 
Jonathan Jekeli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jonathan Jekeli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 329
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't you handling this in the bean instead of polluting the JSP?
 
Jonathan Jekeli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic