RE: Formatting form data inside the *view* (JSP's)

2003-08-28 Thread Steve Raeburn
The Struts bean:write tag offers a format attribute (or formatKey if you
want to use a resource file).
But JSTL would be a better option if you can use it in your environment.

Steve

http://www.ninsky.com/struts/



 -Original Message-
 From: Sasha Borodin [mailto:[EMAIL PROTECTED]
 Sent: August 27, 2003 8:43 AM
 To: Struts Users Mailing List
 Subject: Formatting form data inside the *view* (JSP's)


 Thought I'd throw this out in the middle of the week again...

 Kind of a conceptual question:  how do you format Dates, Numbers,
 Currencies, etc. for *form fields* inside the JSP?

 I know I could do in in the ActionForm getters, but:
 1.  I don't know the locate of the user at that point
 2.  I'd have to recompile the ActionForm every time I want to make a
 change to the *view* - seems like a bad practice.

 What I'm looking to achieve is something similar to fmt:format JSTL tag,
 where you can specify a format mask, or even a format style defined
 elsewhere.

 Thanks,

 -Sasha

 On 8/22/03 12:30, Sasha Borodin [EMAIL PROTECTED] wrote:

  I would like to state a basic assumption I deduced in learning
 struts, then
  pose a question.
 
  Assumption:  ActionForm property getters and setters should
 return and take
  Strings.
 
  My initial impulse was to try passing the actual data types
 (Dates, Numbers,
  etc.); however, the Struts mechanism seems to pass Strings to
 the ActionForm
  setter methods on form submission (which throws a conversion
 Exception of
  course). Then I tried making the setters take Strings, and
 getters return
  the actual data types, but this seemed to confuse the introspection
  mechanism; plus I didn't see any way to apply formatting inside the
  html:text tags (like you can in JSTL's fmt:format tags).
 
  Question:  How does one handle formatting data (custom
 formatting or i18n)
  for (pre/re)population of a form?
 
  Ex.:  An update form; a user's information is loaded from the
 database into
  classes (Strings, Dates, Numbers, etc.).  If you want to format
 this data,
  you have to do it in the Model, as the ActionForm only takes and gives
  Strings - which seems to be a Bad Practice.  Even if you had additional
  special setters for the explicit purpose of populating the
 ActionForm from
  original data types, you still don't know what Locale the
 client is from.
 
  Is my assumption incorrect?  Is there a basic flaw in my
 understanding of
  the use of ActionForm?  Or there an actual short-coming, and workaround?
 
  In short, How Can You Format Data For Strut's Form Tags Inside
 The Actual
  JSP :-) ?
 
  Thank you for any input.
 
  -Sasha
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Formatting form data inside the *view* (JSP's)

2003-08-28 Thread Sasha Borodin
That's what I use when just outputting the contents of a bean; but I'm
trying to format the data in form fields.

If I can't combine html:text and bean:write (or JSTL's fmt:format)
tags, is there another way to achieve this?

Thanks,

-Sasha

On 8/27/03 11:17, Steve Raeburn [EMAIL PROTECTED] wrote:

 The Struts bean:write tag offers a format attribute (or formatKey if you
 want to use a resource file).
 But JSTL would be a better option if you can use it in your environment.
 
 Steve
 
 http://www.ninsky.com/struts/
 
 
 
 -Original Message-
 From: Sasha Borodin [mailto:[EMAIL PROTECTED]
 Sent: August 27, 2003 8:43 AM
 To: Struts Users Mailing List
 Subject: Formatting form data inside the *view* (JSP's)
 
 
 Thought I'd throw this out in the middle of the week again...
 
 Kind of a conceptual question:  how do you format Dates, Numbers,
 Currencies, etc. for *form fields* inside the JSP?
 
 I know I could do in in the ActionForm getters, but:
 1.  I don't know the locate of the user at that point
 2.  I'd have to recompile the ActionForm every time I want to make a
 change to the *view* - seems like a bad practice.
 
 What I'm looking to achieve is something similar to fmt:format JSTL tag,
 where you can specify a format mask, or even a format style defined
 elsewhere.
 
 Thanks,
 
 -Sasha
 
 On 8/22/03 12:30, Sasha Borodin [EMAIL PROTECTED] wrote:
 
 I would like to state a basic assumption I deduced in learning
 struts, then
 pose a question.
 
 Assumption:  ActionForm property getters and setters should
 return and take
 Strings.
 
 My initial impulse was to try passing the actual data types
 (Dates, Numbers,
 etc.); however, the Struts mechanism seems to pass Strings to
 the ActionForm
 setter methods on form submission (which throws a conversion
 Exception of
 course). Then I tried making the setters take Strings, and
 getters return
 the actual data types, but this seemed to confuse the introspection
 mechanism; plus I didn't see any way to apply formatting inside the
 html:text tags (like you can in JSTL's fmt:format tags).
 
 Question:  How does one handle formatting data (custom
 formatting or i18n)
 for (pre/re)population of a form?
 
 Ex.:  An update form; a user's information is loaded from the
 database into
 classes (Strings, Dates, Numbers, etc.).  If you want to format
 this data,
 you have to do it in the Model, as the ActionForm only takes and gives
 Strings - which seems to be a Bad Practice.  Even if you had additional
 special setters for the explicit purpose of populating the
 ActionForm from
 original data types, you still don't know what Locale the
 client is from.
 
 Is my assumption incorrect?  Is there a basic flaw in my
 understanding of
 the use of ActionForm?  Or there an actual short-coming, and workaround?
 
 In short, How Can You Format Data For Strut's Form Tags Inside
 The Actual
 JSP :-) ?
 
 Thank you for any input.
 
 -Sasha
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Formatting form data inside the *view* (JSP's)

2003-08-28 Thread Brandon Goodin
yes,

you can use jstl to locate your form. then you can access it's properties
via el and use the jstl tags for display.

Here is the jsp code to accomplish this

 code start 
[EMAIL PROTECTED] prefix=c uri=/WEB-INF/tld/c.tld %

c:set
var=formName
value=${requestScope['org.apache.struts.action.mapping.instance'].name}/

c:set
var=formScope
value=${requestScope['org.apache.struts.action.mapping.instance'].scope}
/

c:if test=${formScope=='request'}
c:set
var=form
value=${requestScope[formName]} scope=request /
/c:if
c:if test=${formScope=='session'}
c:set
var=form
value=${sessionScope[formName]} scope=request /
/c:if
--- code end ---

I usually place this code in a jsp and include it my page when i need to
expose the FormBean easily to the page.

ex. jsp:include page=/jsp/common/form.jsp /

Then i use the following syntax in my page:

c:out value=${form.myValue}/

This would allow you to use all the jstl stuff to format values stored in
your FormBean.

Brandon Goodin

 -Original Message-
 From: Sasha Borodin [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, August 27, 2003 9:29 PM
 To: Struts Users Mailing List
 Subject: Re: Formatting form data inside the *view* (JSP's)


 That's what I use when just outputting the contents of a bean; but I'm
 trying to format the data in form fields.

 If I can't combine html:text and bean:write (or JSTL's fmt:format)
 tags, is there another way to achieve this?

 Thanks,

 -Sasha

 On 8/27/03 11:17, Steve Raeburn [EMAIL PROTECTED] wrote:

  The Struts bean:write tag offers a format attribute (or
 formatKey if you
  want to use a resource file).
  But JSTL would be a better option if you can use it in your environment.
 
  Steve
 
  http://www.ninsky.com/struts/
 
 
 
  -Original Message-
  From: Sasha Borodin [mailto:[EMAIL PROTECTED]
  Sent: August 27, 2003 8:43 AM
  To: Struts Users Mailing List
  Subject: Formatting form data inside the *view* (JSP's)
 
 
  Thought I'd throw this out in the middle of the week again...
 
  Kind of a conceptual question:  how do you format Dates, Numbers,
  Currencies, etc. for *form fields* inside the JSP?
 
  I know I could do in in the ActionForm getters, but:
  1.  I don't know the locate of the user at that point
  2.  I'd have to recompile the ActionForm every time I want
 to make a
  change to the *view* - seems like a bad practice.
 
  What I'm looking to achieve is something similar to
 fmt:format JSTL tag,
  where you can specify a format mask, or even a format style defined
  elsewhere.
 
  Thanks,
 
  -Sasha
 
  On 8/22/03 12:30, Sasha Borodin [EMAIL PROTECTED] wrote:
 
  I would like to state a basic assumption I deduced in learning
  struts, then
  pose a question.
 
  Assumption:  ActionForm property getters and setters should
  return and take
  Strings.
 
  My initial impulse was to try passing the actual data types
  (Dates, Numbers,
  etc.); however, the Struts mechanism seems to pass Strings to
  the ActionForm
  setter methods on form submission (which throws a conversion
  Exception of
  course). Then I tried making the setters take Strings, and
  getters return
  the actual data types, but this seemed to confuse the introspection
  mechanism; plus I didn't see any way to apply formatting inside the
  html:text tags (like you can in JSTL's fmt:format tags).
 
  Question:  How does one handle formatting data (custom
  formatting or i18n)
  for (pre/re)population of a form?
 
  Ex.:  An update form; a user's information is loaded from the
  database into
  classes (Strings, Dates, Numbers, etc.).  If you want to format
  this data,
  you have to do it in the Model, as the ActionForm only takes and gives
  Strings - which seems to be a Bad Practice.  Even if you had
 additional
  special setters for the explicit purpose of populating the
  ActionForm from
  original data types, you still don't know what Locale the
  client is from.
 
  Is my assumption incorrect?  Is there a basic flaw in my
  understanding of
  the use of ActionForm?  Or there an actual short-coming, and
 workaround?
 
  In short, How Can You Format Data For Strut's Form Tags Inside
  The Actual
  JSP :-) ?
 
  Thank you for any input.
 
  -Sasha
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail

RE: Formatting form data inside the *view* (JSP's)

2003-08-28 Thread Jonathan Lehr
Hi Sasha,

An alternative approach would be to create a generic mechanism to
populate the ActionForm with properly formatted string values. The idea
here is to write a method that transfers values from a bean to an
ActionForm, automatically applying default type conversion and
formatting based on the bean's property types. Another method can be
added to provide a way to override the default formatting behavior.

I write about this subject extensively in my book Jakarta Pitfalls
(Wiley). Chapter 2, ActionForms, begins with this problem and its
solution. Later sections in the same chapter show how to extend the
mechanism to automatically validate inbound request values (without the
need for declarative specification), and then populate the JavaBean
with converted values using the inverse of the formatting scheme.

The value of this approach is that you don't have to encode the
formatting logic in your JSPs at all. All the formatting code is in one
place, and new JSPs automatically get the formatting behavior without
adding any new code. It helps ensure consistency too, especially if you
have a lot of pages/developers.

A free, downloadable implementation is provided in the example
solutions for Chapter 2, at
http://www.wiley.com/compbooks/dudney/jakarta/index.html under the
Chapters 2,3,4 link.

I'm a bit puzzled that you say that you can't get the user's locale in
your ActionForm. I would think you should be able to do something like
this in your Action to get the locale and set it on the form instance:

public ActionForward execute(...) {
...
Locale currLocale = (Locale) 
request.getSession().getAttribute(Globals.LOCALE_KEY);
form.setLocale(currLocale);
...
}

Jonathan


 -Original Message-
 From: Sasha Borodin [mailto:[EMAIL PROTECTED]
 Sent: August 27, 2003 8:43 AM
 To: Struts Users Mailing List
 Subject: Formatting form data inside the *view* (JSP's)


 Thought I'd throw this out in the middle of the week again...

 Kind of a conceptual question:  how do you format Dates, Numbers,
 Currencies, etc. for *form fields* inside the JSP?

 I know I could do in in the ActionForm getters, but:
 1.  I don't know the locate of the user at that point
 2.  I'd have to recompile the ActionForm every time I want to 
make a
 change to the *view* - seems like a bad practice.

 What I'm looking to achieve is something similar to fmt:format JSTL

tag,
 where you can specify a format mask, or even a format style defined
 elsewhere.

 Thanks,

 -Sasha

 On 8/22/03 12:30, Sasha Borodin [EMAIL PROTECTED] wrote:

  I would like to state a basic assumption I deduced in learning
 struts, then
  pose a question.
 
  Assumption:  ActionForm property getters and setters should
 return and take
  Strings.
 
  My initial impulse was to try passing the actual data types
 (Dates, Numbers,
  etc.); however, the Struts mechanism seems to pass Strings to
 the ActionForm
  setter methods on form submission (which throws a conversion
 Exception of
  course). Then I tried making the setters take Strings, and
 getters return
  the actual data types, but this seemed to confuse the introspection
  mechanism; plus I didn't see any way to apply formatting inside the
  html:text tags (like you can in JSTL's fmt:format tags).
 
  Question:  How does one handle formatting data (custom
 formatting or i18n)
  for (pre/re)population of a form?
 
  Ex.:  An update form; a user's information is loaded from the
 database into
  classes (Strings, Dates, Numbers, etc.).  If you want to format
 this data,
  you have to do it in the Model, as the ActionForm only takes and 
gives
  Strings - which seems to be a Bad Practice.  Even if you had 
additional
  special setters for the explicit purpose of populating the
 ActionForm from
  original data types, you still don't know what Locale the
 client is from.
 
  Is my assumption incorrect?  Is there a basic flaw in my
 understanding of
  the use of ActionForm?  Or there an actual short-coming, and 
workaround?
 
  In short, How Can You Format Data For Strut's Form Tags Inside
 The Actual
  JSP :-) ?
 
  Thank you for any input.
 
  -Sasha

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Formatting form data inside the *view* (JSP's)

2003-08-28 Thread Kris Schneider
Haven't tried this yet, but it's a bit more concise and should be 
equivalent:

%@ taglib prefix=c uri=http://java.sun.com/jstl/core; %

jsp:useBean id=configHelper
 class=org.apache.struts.config.ConfigHelper/
c:set target=${configHelper}
   property=request
   value=${pageContext.request}/
c:set var=form value=${configHelper.actionForm}/
Brandon Goodin wrote:
yes,

you can use jstl to locate your form. then you can access it's properties
via el and use the jstl tags for display.
Here is the jsp code to accomplish this

 code start 
[EMAIL PROTECTED] prefix=c uri=/WEB-INF/tld/c.tld %
c:set
var=formName
value=${requestScope['org.apache.struts.action.mapping.instance'].name}/
c:set
var=formScope
value=${requestScope['org.apache.struts.action.mapping.instance'].scope}
/
c:if test=${formScope=='request'}
c:set
var=form
value=${requestScope[formName]} scope=request /
/c:if
c:if test=${formScope=='session'}
c:set
var=form
value=${sessionScope[formName]} scope=request /
/c:if
--- code end ---
I usually place this code in a jsp and include it my page when i need to
expose the FormBean easily to the page.
ex. jsp:include page=/jsp/common/form.jsp /

Then i use the following syntax in my page:

c:out value=${form.myValue}/

This would allow you to use all the jstl stuff to format values stored in
your FormBean.
Brandon Goodin


-Original Message-
From: Sasha Borodin [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 27, 2003 9:29 PM
To: Struts Users Mailing List
Subject: Re: Formatting form data inside the *view* (JSP's)
That's what I use when just outputting the contents of a bean; but I'm
trying to format the data in form fields.
If I can't combine html:text and bean:write (or JSTL's fmt:format)
tags, is there another way to achieve this?
Thanks,

-Sasha

On 8/27/03 11:17, Steve Raeburn [EMAIL PROTECTED] wrote:


The Struts bean:write tag offers a format attribute (or
formatKey if you

want to use a resource file).
But JSTL would be a better option if you can use it in your environment.
Steve

http://www.ninsky.com/struts/




-Original Message-
From: Sasha Borodin [mailto:[EMAIL PROTECTED]
Sent: August 27, 2003 8:43 AM
To: Struts Users Mailing List
Subject: Formatting form data inside the *view* (JSP's)
Thought I'd throw this out in the middle of the week again...

Kind of a conceptual question:  how do you format Dates, Numbers,
Currencies, etc. for *form fields* inside the JSP?
I know I could do in in the ActionForm getters, but:
   1.  I don't know the locate of the user at that point
   2.  I'd have to recompile the ActionForm every time I want
to make a

change to the *view* - seems like a bad practice.

What I'm looking to achieve is something similar to
fmt:format JSTL tag,

where you can specify a format mask, or even a format style defined
elsewhere.
Thanks,

-Sasha

On 8/22/03 12:30, Sasha Borodin [EMAIL PROTECTED] wrote:


I would like to state a basic assumption I deduced in learning
struts, then

pose a question.

Assumption:  ActionForm property getters and setters should
return and take

Strings.

My initial impulse was to try passing the actual data types
(Dates, Numbers,

etc.); however, the Struts mechanism seems to pass Strings to
the ActionForm

setter methods on form submission (which throws a conversion
Exception of

course). Then I tried making the setters take Strings, and
getters return

the actual data types, but this seemed to confuse the introspection
mechanism; plus I didn't see any way to apply formatting inside the
html:text tags (like you can in JSTL's fmt:format tags).
Question:  How does one handle formatting data (custom
formatting or i18n)

for (pre/re)population of a form?

Ex.:  An update form; a user's information is loaded from the
database into

classes (Strings, Dates, Numbers, etc.).  If you want to format
this data,

you have to do it in the Model, as the ActionForm only takes and gives
Strings - which seems to be a Bad Practice.  Even if you had
additional

special setters for the explicit purpose of populating the
ActionForm from

original data types, you still don't know what Locale the
client is from.

Is my assumption incorrect?  Is there a basic flaw in my
understanding of

the use of ActionForm?  Or there an actual short-coming, and
workaround?

In short, How Can You Format Data For Strut's Form Tags Inside
The Actual

JSP :-) ?

Thank you for any input.

-Sasha
--
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Formatting form data inside the *view* (JSP's)

2003-08-28 Thread Sasha Borodin
Kris, Brandon:

Thank you for your replies; I understand your code, and am able to access
the form properties from within the JSP.

My question is more about combining formatting tags (like bean:message and
fmt:format with html:text and the like.  I want to format the default
values of form elements (the part that Struts automates).  This is where I'm
coming up short on ideas.

Thanks,

-Sasha

On 8/27/03 23:53, Kris Schneider [EMAIL PROTECTED] wrote:

 Haven't tried this yet, but it's a bit more concise and should be
 equivalent:
 
 %@ taglib prefix=c uri=http://java.sun.com/jstl/core; %
 
 jsp:useBean id=configHelper
 class=org.apache.struts.config.ConfigHelper/
 c:set target=${configHelper}
   property=request
   value=${pageContext.request}/
 c:set var=form value=${configHelper.actionForm}/
 
 Brandon Goodin wrote:
 yes,
 
 you can use jstl to locate your form. then you can access it's properties
 via el and use the jstl tags for display.
 
 Here is the jsp code to accomplish this
 
  code start 
 [EMAIL PROTECTED] prefix=c uri=/WEB-INF/tld/c.tld %
 
 c:set
 var=formName
 value=${requestScope['org.apache.struts.action.mapping.instance'].name}/
 
 c:set
 var=formScope
 value=${requestScope['org.apache.struts.action.mapping.instance'].scope}
 /
 
 c:if test=${formScope=='request'}
 c:set
 var=form
 value=${requestScope[formName]} scope=request /
 /c:if
 c:if test=${formScope=='session'}
 c:set
 var=form
 value=${sessionScope[formName]} scope=request /
 /c:if
 --- code end ---
 
 I usually place this code in a jsp and include it my page when i need to
 expose the FormBean easily to the page.
 
 ex. jsp:include page=/jsp/common/form.jsp /
 
 Then i use the following syntax in my page:
 
 c:out value=${form.myValue}/
 
 This would allow you to use all the jstl stuff to format values stored in
 your FormBean.
 
 Brandon Goodin
 
 
 -Original Message-
 From: Sasha Borodin [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, August 27, 2003 9:29 PM
 To: Struts Users Mailing List
 Subject: Re: Formatting form data inside the *view* (JSP's)
 
 
 That's what I use when just outputting the contents of a bean; but I'm
 trying to format the data in form fields.
 
 If I can't combine html:text and bean:write (or JSTL's fmt:format)
 tags, is there another way to achieve this?
 
 Thanks,
 
 -Sasha
 
 On 8/27/03 11:17, Steve Raeburn [EMAIL PROTECTED] wrote:
 
 
 The Struts bean:write tag offers a format attribute (or
 
 formatKey if you
 
 want to use a resource file).
 But JSTL would be a better option if you can use it in your environment.
 
 Steve
 
 http://www.ninsky.com/struts/
 
 
 
 
 -Original Message-
 From: Sasha Borodin [mailto:[EMAIL PROTECTED]
 Sent: August 27, 2003 8:43 AM
 To: Struts Users Mailing List
 Subject: Formatting form data inside the *view* (JSP's)
 
 
 Thought I'd throw this out in the middle of the week again...
 
 Kind of a conceptual question:  how do you format Dates, Numbers,
 Currencies, etc. for *form fields* inside the JSP?
 
 I know I could do in in the ActionForm getters, but:
1.  I don't know the locate of the user at that point
2.  I'd have to recompile the ActionForm every time I want
 
 to make a
 
 change to the *view* - seems like a bad practice.
 
 What I'm looking to achieve is something similar to
 
 fmt:format JSTL tag,
 
 where you can specify a format mask, or even a format style defined
 elsewhere.
 
 Thanks,
 
 -Sasha
 
 On 8/22/03 12:30, Sasha Borodin [EMAIL PROTECTED] wrote:
 
 
 I would like to state a basic assumption I deduced in learning
 
 struts, then
 
 pose a question.
 
 Assumption:  ActionForm property getters and setters should
 
 return and take
 
 Strings.
 
 My initial impulse was to try passing the actual data types
 
 (Dates, Numbers,
 
 etc.); however, the Struts mechanism seems to pass Strings to
 
 the ActionForm
 
 setter methods on form submission (which throws a conversion
 
 Exception of
 
 course). Then I tried making the setters take Strings, and
 
 getters return
 
 the actual data types, but this seemed to confuse the introspection
 mechanism; plus I didn't see any way to apply formatting inside the
 html:text tags (like you can in JSTL's fmt:format tags).
 
 Question:  How does one handle formatting data (custom
 
 formatting or i18n)
 
 for (pre/re)population of a form?
 
 Ex.:  An update form; a user's information is loaded from the
 
 database into
 
 classes (Strings, Dates, Numbers, etc.).  If you want to format
 
 this data,
 
 you have to do it in the Model, as the ActionForm only takes and gives
 Strings - which seems to be a Bad Practice.  Even if you had
 
 additional
 
 special setters for the explicit purpose of populating the
 
 ActionForm from
 
 original data types, you still don't know what Locale the
 
 client is from.
 
 Is my assumption incorrect?  Is there a basic flaw in my
 
 understanding of
 
 the use of ActionForm?  Or there an actual short-coming, and
 
 workaround

Re: Formatting form data inside the *view* (JSP's)

2003-08-28 Thread Sasha Borodin
Jonathan,

I like your system; if I understand it correctly, it automates conversion
between Strings and other primitive data types.  However, this formatting
still takes place inside the ActionForm, not the JSP.

I guess I've traditionally had a different view of best practice.  To me,
it seems appropriate to let the page designer dictate the format of Dates,
Numbers, etc.  If you ever want to change those formats, you've got to
recompile the ActionForm; and if you want to have different formats using
the same form, you'd be out of luck.  Right?

Thanks for taking the time to respond.

All:  Is the consensus to keep the formatting out of the JSP and in the
ActionForm?  That doesn't seem to jive...everything else (localized
messages, regular bean values) have ways of being formatted inside the JSP.

-Sasha

P.S.
 I'm a bit puzzled that you say that you can't get the user's locale in
 your ActionForm.
You're right, my mistake.

On 8/27/03 23:51, Jonathan Lehr [EMAIL PROTECTED] wrote:

 Hi Sasha,
 
 An alternative approach would be to create a generic mechanism to
 populate the ActionForm with properly formatted string values. The idea
 here is to write a method that transfers values from a bean to an
 ActionForm, automatically applying default type conversion and
 formatting based on the bean's property types. Another method can be
 added to provide a way to override the default formatting behavior.
 
 I write about this subject extensively in my book Jakarta Pitfalls
 (Wiley). Chapter 2, ActionForms, begins with this problem and its
 solution. Later sections in the same chapter show how to extend the
 mechanism to automatically validate inbound request values (without the
 need for declarative specification), and then populate the JavaBean
 with converted values using the inverse of the formatting scheme.
 
 The value of this approach is that you don't have to encode the
 formatting logic in your JSPs at all. All the formatting code is in one
 place, and new JSPs automatically get the formatting behavior without
 adding any new code. It helps ensure consistency too, especially if you
 have a lot of pages/developers.
 
 A free, downloadable implementation is provided in the example
 solutions for Chapter 2, at
 http://www.wiley.com/compbooks/dudney/jakarta/index.html under the
 Chapters 2,3,4 link.
 
 I'm a bit puzzled that you say that you can't get the user's locale in
 your ActionForm. I would think you should be able to do something like
 this in your Action to get the locale and set it on the form instance:
 
 public ActionForward execute(...) {
   ...
   Locale currLocale = (Locale)
   request.getSession().getAttribute(Globals.LOCALE_KEY);
   form.setLocale(currLocale);
   ...
 }
 
 Jonathan
 
 
 -Original Message-
 From: Sasha Borodin [mailto:[EMAIL PROTECTED]
 Sent: August 27, 2003 8:43 AM
 To: Struts Users Mailing List
 Subject: Formatting form data inside the *view* (JSP's)
 
 
 Thought I'd throw this out in the middle of the week again...
 
 Kind of a conceptual question:  how do you format Dates, Numbers,
 Currencies, etc. for *form fields* inside the JSP?
 
 I know I could do in in the ActionForm getters, but:
 1.  I don't know the locate of the user at that point
 2.  I'd have to recompile the ActionForm every time I want to
 make a
 change to the *view* - seems like a bad practice.
 
 What I'm looking to achieve is something similar to fmt:format JSTL
 
 tag,
 where you can specify a format mask, or even a format style defined
 elsewhere.
 
 Thanks,
 
 -Sasha
 
 On 8/22/03 12:30, Sasha Borodin [EMAIL PROTECTED] wrote:
 
 I would like to state a basic assumption I deduced in learning
 struts, then
 pose a question.
 
 Assumption:  ActionForm property getters and setters should
 return and take
 Strings.
 
 My initial impulse was to try passing the actual data types
 (Dates, Numbers,
 etc.); however, the Struts mechanism seems to pass Strings to
 the ActionForm
 setter methods on form submission (which throws a conversion
 Exception of
 course). Then I tried making the setters take Strings, and
 getters return
 the actual data types, but this seemed to confuse the introspection
 mechanism; plus I didn't see any way to apply formatting inside the
 html:text tags (like you can in JSTL's fmt:format tags).
 
 Question:  How does one handle formatting data (custom
 formatting or i18n)
 for (pre/re)population of a form?
 
 Ex.:  An update form; a user's information is loaded from the
 database into
 classes (Strings, Dates, Numbers, etc.).  If you want to format
 this data,
 you have to do it in the Model, as the ActionForm only takes and
 gives
 Strings - which seems to be a Bad Practice.  Even if you had
 additional
 special setters for the explicit purpose of populating the
 ActionForm from
 original data types, you still don't know what Locale the
 client is from.
 
 Is my assumption incorrect?  Is there a basic flaw in my
 understanding of
 the use of ActionForm

Formatting form data inside the *view* (JSP's)

2003-08-27 Thread Sasha Borodin
Thought I'd throw this out in the middle of the week again...

Kind of a conceptual question:  how do you format Dates, Numbers,
Currencies, etc. for *form fields* inside the JSP?

I know I could do in in the ActionForm getters, but:
1.  I don't know the locate of the user at that point
2.  I'd have to recompile the ActionForm every time I want to make a
change to the *view* - seems like a bad practice.

What I'm looking to achieve is something similar to fmt:format JSTL tag,
where you can specify a format mask, or even a format style defined
elsewhere.

Thanks,

-Sasha

On 8/22/03 12:30, Sasha Borodin [EMAIL PROTECTED] wrote:

 I would like to state a basic assumption I deduced in learning struts, then
 pose a question.
 
 Assumption:  ActionForm property getters and setters should return and take
 Strings.  
 
 My initial impulse was to try passing the actual data types (Dates, Numbers,
 etc.); however, the Struts mechanism seems to pass Strings to the ActionForm
 setter methods on form submission (which throws a conversion Exception of
 course). Then I tried making the setters take Strings, and getters return
 the actual data types, but this seemed to confuse the introspection
 mechanism; plus I didn't see any way to apply formatting inside the
 html:text tags (like you can in JSTL's fmt:format tags).
 
 Question:  How does one handle formatting data (custom formatting or i18n)
 for (pre/re)population of a form?
 
 Ex.:  An update form; a user's information is loaded from the database into
 classes (Strings, Dates, Numbers, etc.).  If you want to format this data,
 you have to do it in the Model, as the ActionForm only takes and gives
 Strings - which seems to be a Bad Practice.  Even if you had additional
 special setters for the explicit purpose of populating the ActionForm from
 original data types, you still don't know what Locale the client is from.
 
 Is my assumption incorrect?  Is there a basic flaw in my understanding of
 the use of ActionForm?  Or there an actual short-coming, and workaround?
 
 In short, How Can You Format Data For Strut's Form Tags Inside The Actual
 JSP :-) ?
 
 Thank you for any input.
 
 -Sasha
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]