You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Sean Schofield <se...@gmail.com> on 2005/11/30 19:33:28 UTC

Using converters in non-JSF related code.

Has anyone ever used a JSF converter in code that wasn't specifically
related to JSF?  The reason why I am asking is that we are migrating
an application to JSF and a portion of the pages are in JSF but a
portion are still in Struts.

Two possible ideas come to mind:

1.) Use the converter's getAsString method inside of a static utility method

2.) Move the logic from the getAsString method to a static utility method.

I suppose approach #2 is less of a hack since you avoid FacesContext
and other JSF specific stuff in your static helper.

Any other thoughts or approaches?

TIA,

sean

Re: Using converters in non-JSF related code.

Posted by Mike Kienenberger <mk...@gmail.com>.
There's not much in a converter and there shouldn't be any reason why
you couldn't do this.
However, since you're having to pass in a FacesContext and a
UIComponent, I think you'd have to reimplement a lot of unnecesary
support classes.

I'm not sure I'd stick it in a static utility method, but maybe that
makes sense in your use cases.

I'd probably go with a presentation-layer-independent converter class.
 Then subclass it to create the JSF converter.

When I look at my own JSF converters, this is a trivial refactoring. 
I've already got the non-JSF conversions being handled in separate
methods which are called by the getAs methods.

On 11/30/05, Sean Schofield <se...@gmail.com> wrote:
> Has anyone ever used a JSF converter in code that wasn't specifically
> related to JSF?  The reason why I am asking is that we are migrating
> an application to JSF and a portion of the pages are in JSF but a
> portion are still in Struts.
>
> Two possible ideas come to mind:
>
> 1.) Use the converter's getAsString method inside of a static utility method
>
> 2.) Move the logic from the getAsString method to a static utility method.
>
> I suppose approach #2 is less of a hack since you avoid FacesContext
> and other JSF specific stuff in your static helper.
>
> Any other thoughts or approaches?
>
> TIA,
>
> sean
>