aspose file tools*
The moose likes Struts and the fly likes Struts 1 - Doing math on the value of a struts bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1 - Doing math on the value of a struts bean" Watch "Struts 1 - Doing math on the value of a struts bean" New topic
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: 61766
    
  67

Why aren't you handling this in the bean instead of polluting the JSP?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 1 - Doing math on the value of a struts bean