I handled this by code generation. My Cayenne data-model + Velocity
= N converter.java files + 1 faces-config file. I'll be interested to
here if you come up with a better way.
You might also be able to do something with this. Not sure if it's
directly relevent, but maybe it'll give you new ideas.
public Converter getConverter()
{
Application app = FacesContext.getCurrentInstance().getApplication();
String converterID = "myConverter";
app.addConverter(converterID, "mypackage.myConverter");
MyConverter converter = (MyConverter)app.createConverter(converterID);
// configure converter here
return converter;
}
< h:selectOneMenu
converter="#{backingBean.converter}"
On 7/21/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> 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
>