views:

38

answers:

1

I have an app built on Model-Glue: Unity that contains some search forms. I need to trim leading and trailing spaces from search strings before using them to query the database. I'm also keeping the search terms in a bean that a user can save and re-use.

My problem is that I am unsure where to perform that trim(). The bean seems to be the wrong place for it, as I'm keeping the bean simple (no logic). Normally I would take care of that when updating the bean, but I'm using MakeEventBean to keep things simple. Re-touching all of the data in the Service layer seems an unnecessary layer of overhead. And, lastly, doing it in the datalayer with the actual SQL query doesn't seem right either. It'll work, but the information in my search bean will still be wrong.

What have you done in such cases?

+2  A: 

Disclaimer: I'm not a MG user, so I'm not sure if this will be good and possible approach. Just want to share the idea.

In case of Transfer ORM beans I do such specific things in decorators which extend auto-generated beans.

For example, I can easily override setter setSearchPhrase(phrase), where trim the argument value and invoke original method.

Sergii
Not using an ORM, but that's an interesting idea.
Al Everett