Possible Duplicate:
Easy way of populating Javabeans based on request parameters
Hi,
I have a Java Object with a set of search parameters, sth. like
public class SearchRequest {
private String customerName;
private String city;
...
}
This request has to be filled by a servet request.
But instead of writing code like
...
SearchRequest searchRequest = new SearchRequest();
if (request.getParameter("customerName") != null)
{
searchRequest.setCustomerName(request.getParameter("customerName"));
}
if (request.getParameter("city") != null)
{
searchRequest.setCity(request.getParameter("city"));
}
... I'm looking for a more generic way.
I was checking the mapping tool Dozer but did not find a nice way how to handle this mapping.
Now I think reflection would be a choice. Is this true? If so does anyone has a code sniplet how this can be done with reflection?