Rick Reumann wrote:

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 );

This I use the same way.

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);

Please take a look to other email that I sent earlier - there i shared my experince with some special "mediator" objects that are responsible to move the data between Forms and BO.

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)

I do the same - inittialization part is in plugin so it's done only once on the load of the application. All my emails are with a bit bitter tone because I just expected much more from ActionForms, and now I'm a bit disapointed, especially about data conversions and populations ...

But JSF is on the horizon ...

Regards
Borislav


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

Reply via email to