• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic