4 Replies Latest reply on Apr 13, 2007 5:57 PM by Pete Muir

    @Convert and overriding standard types

    Jim Hazen Expert

      I've written a Seam component JSF Converter. It works great if I specify an <f:converter> tag on my input. However if I specify

      @org.jboss.seam.annotations.jsf.Converter(forClass=String.class)

      and leave off the <f:converter>, the converter isn't called even if there is a String value binding. Any tips? Is Seam not able to override the JSF defaults? I suppose forClass=Foo.class (no default converter) could be an intended usage patter, but figured I'd ask those in the know.

      I'm on Seam 1.2.1GA

        • 1. Re: @Convert and overriding standard types
          Pete Muir Master

          This is working fine for me. Looks to me like JSF (1.2 RI) doesn't call getAsString but does call getAsObject - I guess it doesn't call the converter if the value is already a String.

          • 2. Re: @Convert and overriding standard types
            Pete Muir Master

            The spec isn't really very clear on this but I guess it makes sense

            • 3. Re: @Convert and overriding standard types
              Jim Hazen Expert

              Hmm, what I was seeing on JBoss 4.0.5, which should be MyFaces on JSF 1.1, is that my converter wasn't being called at all in either direction when I tried to override forClass=String.class.

              What I've written is a quick converter to translate empty Strings into null. This makes my DB happier (as well as my equals()). Currently when I take input from a form and don't populate fields, they become empty strings. I'm trying to replace that default semantic with my Seam @Convert converter.

              Works great if I specify a <f:converter> everywhere, but that's kind of a drag. On the whole I still love being able to register a JSF converter with two annotations. Thanks Seam.

              PS: Perhaps this is an issue with MyFaces. As you say, the spec may not be clear. I'm looking forward to JBoss 4.2 and the 1.2 RI. (yea I know I could hack 4.0.5, but I'm not gunna :)

              • 4. Re: @Convert and overriding standard types
                Pete Muir Master

                CVS is now on 4.2.0.CR1 so that's what I'm working off ;)

                I guess MyFaces doesn't run converters in either directions for the Strings - this should really be specified by the spec - I guess for JSF 2.0.

                An option (not a great one admittedly) is to create an s:validateAll style component to apply your converter to it's children to get around this...