Action Form getter methods and the user's locale. I posed a question a few days ago that I realize probably was not worded very clearly.

Ted Husted

From a MVC perspective, it's really best to think of the ActionForm as a denizen of the control layer. It is a data transfer object that is used to capture input posted by the view and ready it for transfer to the model layer. As such, it's best thought of a dumb data carrier -- an encapsulation of the input and other output other objects need to do their jobs.

If an application is localized, then the localization should be represented in the model. So, the best place thing is for the ActionForm to be populate with pre-localized data before it is sent down to the presentation layer.

Struts provides a standard Locale object in the user's session that you can hand up to the model so that it can return the localized data.

Another approach would be to add the locale object to the ActionForm and have the getters use that to localize the property when it is returned. The request is passed to the Reset method, so you can have the ActionForm grab the locale from the session whenever reset it called. In this case, you might want to have both getAmount and getAmountDisplay properties, to return either the "raw" or formatted versions. But, IMHO, its preferable to have only getAmountDisplay on the ActionForm and then put the getAmount and getAmountDisplay properties on the model bean instead.

HTH, Ted.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact