Thanks, Craig.   I probably should have been more clear and mentioned
I was talking about converters registered by class/type rather than a
converter explicitly configured on a component (via a converter method
attribute or as a child element).

Hopefully, some future JSF spec will allow managed-property values on
converters.

On 12/2/05, Craig McClanahan <[EMAIL PROTECTED]> wrote:
> On 12/2/05, Mike Kienenberger <[EMAIL PROTECTED]> wrote:
> > Craig, I think we're talking about two slightly different things.
> >
> > I'm talking about creating a JSF Converter as a subclass of some kind
> > of generic converter.   You'd use the generic converter outside of JSF
> > and the JSF converter inside JSF.   That way, you don't need to mock
> > up a FacesContext or UIComponent.
> >
> > I still don't see how you can use dependency injection on a JSF
> > converter inside a JSF application.   What am I missing?   I've got a
> > managed bean (database-backed data source) that I'd love to inject
> > into my converters.   Currently I have to ask JSF for the bean by name
> > inside my converter code.....
>
>  One thing to note is that the "converter" property (at least on the
> standard components) can be value bound to a Converter instance ... which
> could be a managed bean ... which could have a property ... that is
> initialized (via a value binding expression) ... to inject yet another bean.
>  Or, as a concrete example:
>
>  Page1.jsp:
>
>      <h:inputText id="entryDate" ...
> converter="#{entryDateConverter}" .../>
>
>  Managed beans section of faces-config.xml:
>
>      <!-- Declare my Converter instance -->
>      <managed-bean>
>
> <managed-bean-name>entryDateConverter</managed-bean.name>
>
> <managed-bean-class>com.mycompany.mypackage.MyEntryDateConverter</managed-bean-class>
>          <!-- Don't actually store the instance in any scope -->
>          <managed-bean-scope>none</managed-bean-scope>
>          <managed-property>
>              <property-name>special</property-name>
>
> <property-class>com.mycompany.mypackage.MySpecialWIdgetType</property-class>
>              <value>#{injected}</value>
>          </managed-property>
>      </managed-bean>
>
>      <!-- Declare the bean that is injected into my Converter instance -->
>      <managed-bean>
>          <managed-bean-name>injected</managed-bean-name>
>
> <managed-bean-class>com.mycompany.mypackage.MySpecialWidgetType</property-class>
>          <managed-bean-scope>none</managed-bean-scope>
>          ...
>      </managed-bean>
>
>  In other words, managed beans provide a basic but quite functional
> dependency injection framework all by themselves.  If that's not enough,
> Spring includes an adapter so that you could transparently use Spring's
> BeanFactory instead.
>
>  Craig
>
>

Reply via email to