struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: Formatting data for display and parsing to save
Date Thu, 31 Aug 2006 21:36:50 GMT
Givler, Eric wrote:
> I don't know why, but I've been wondering how to handle the issue of presenting formatted
data to a user in a struts-based application.
> 
> That is, is it:
> 
> 1. Backend bean is strongly typed and data is read into this via Service method of some
sort
> 2. Action takes backend data and through a helper object formats it and places into ActionForm
properties as formatted values 
> 3. User enters data
> 4. Validation ensures formatting is ok (Struts Validator or other)
> 5. If ok, helper object parses results and creates business bean (DTO) to persist to
back end
> 6. Invoke service method to store it

That sounds pretty reasonable, yes.

> I've looked at FormDef, but the App I've inherited to fix contains a lot of front-end
code (in JSP) that adds up values and presents them.  Now that the form bean (a map) contains
all Strings, I have to then run <fmt:parse> against all of this data to add it up. 
I guess I could add it up in the Action when I first read the database values and created
some other request attributes, and made sure these attributes were refreshed if I hit save.
 If validation occurs and errors are thrown, where do I get those database values again to
add easily?  I can't add the unparse-able numbers (or I add them as zero)  Do I throw the
DTO into the form bean as a property?

It sounds like your JSPs have a lot of data processing logic in them. 
Ideally, all the data derivation (summing rows, etc.) should happen in 
your application logic -- in an action, or a service the action calls. 
The form bean or other objects you pass to the JSP should have all the 
data needed to display the page, already calculated.

When the form is submitted, you validate all fields and, if any fail, 
redisplay the form in the state it was when it was submitted. It's up to 
you and your requirements whether calculated data should be updated in 
this case, or whether you should (for example) display 'n/a' for fields 
that depend on invalid inputs.

> I'm not sure I like the idea that the Business bean returns the formatted data, which
I've seen in Struts In Action.  Not that I have anything against the book, but if the formatting
is based on a Locale, and a locale is user-based, then it seems like the formatting should
be occurring in the front-end like in JSF, rather than the other way around.

There's a difference between formatting and data aquisition / 
processing. Once you clean up the way data gets to the page, issues 
about how and where to format it for display should be easier to address.

> Also, is there something that works for multi-record entry with formatting as well? 
I didn't understand how form-def was supposed to handle this, and the same issue would apply
with summing the result records (actually sum, min, and max)

I'm not sure how this relates. Perhaps the question is a bit too general.

> I'm all ears for suggestions, and thanks.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message