Borislav Sabev wrote the following on 7/12/2005 3:20 AM:
In fact I'm a bit confused what exactly is the recommended design
pattern in this case ...
My conclusion is really to use Strings,
Yes, you should use Strings in your ActionForms. Then you have your
business object POJO with the correct Data types declared and use
BeanUtils to make the conversion (unless you are one of the big Map
proponents then you don't even have to worry about using a value object,
but I digress):
//copying form bean properties into your value object
BeanUtils.copyProperties( yourValueObject, yourForm );
and if you pull back data from the db and need to enter it in the form
(typically for providing edit functioality) you do the reverse:
BeanUtils.copyProperties( yourForm, yourValueObject);
If you register your own converters, BeanUtils will use those converters
if need be. (By the way, you mentioned you are having to convert twice -
once in the converter and again on the front end - this shouldn't be the
case.)
If it helps I can show you two of my converters.. not sure I'm doing it
that best way but it works. I have a
"CustomValueToSringConverter" Which is used by BeanUtils to look for
certain types like java.util.Date and java.sql.Date and formats them
into the correct String format that I need.
and then I have
"CustomStringToUtilDateConverter" and "CustomStringToSQLDateConverter"
that do the reverse ( take Strings and covert them to appropriate Dates )
Both are registered on Server startup so that I don't have to register
these a bunch of times. This is done in a ServletContextListener...
public void contextInitialized(ServletContextEvent contextEvent) {
ServletContext context = contextEvent.getServletContext();
try {
ConvertUtils.register(new CustomValueToStringConverter("MM/dd/yyyy"),
String.class);
ConvertUtils.register(new CustomStringToSqlDateConverter("MM/dd/yyyy"),
java.sql.Date.class);
...
(By the way I pass in an optional default format in my constructor as
shown above, but my converters have a setFormatPattern(..) method that
can change the format at any time)
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]