Hi,

I implemented a generic object converter for Hibernate using a dummy dao that only needs the ID for the object (in terms of Hibernate) and its class.

So when the object has to be converted to a String, I simply generate a string with the class name and the ID of the object. And when a string needs to be converted to an object, I simply ask Hibernate to load the object whose class and ID is obtained from the previously created string.

I can do this generic thing due to the fact that I'm working with Hibernate, but I think it can be easily extended to whatever scope you need.

Hope it helps ;-)

2005/7/21, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:

There are 29 lookup tables in my db. The selectOneMenu tags of the site are populated via objects that have been mapped to each table using Hibernate.  I want "one converter to rule them all".

getAsString() is done (determine the identifier/pk property of the bean at runtime by querying the OR meta data, call it w/ reflection, return the value as a string).  getAsObject() however is difficult - it needs some way to know which class it must create.

Is there a way to determine this by walking the UIcomponent passed to getAsObject() ?  I can cast it to a HtmlSelectOneMenu but that's as far as I get.

One idea was to extend the tag handler, add a className attribute and pass the value of this attribute to the dynamic converter in an over ridden createConverter().  Despite the fact that this means the class's full java name appears directly in the JSP, I still did this only to find that it only works for the first conversion.  The dynamic converter is recreated for each request, and the createConverter() of the tag class only fires for the first request.

I'm open to the possibility this smart converter is not a smart idea.  Someone throw me a bright idea before I go with the following:

Write 29 classes, each implements getAsObject() - each class inherits getAsString() from 30th class.

Dennis Byrne

Reply via email to