Why aren't multiple Converters allowed on a single value holder?











up vote
3
down vote

favorite












This morning I had reason to try using multiple Converters on an inputText component and realized that this doesn't work.



Does anyone who why JSF only allows a single Converter per ValueHolder? It seems that using a series of Converters would be elegant in several situations.










share|improve this question


















  • 1




    Actually, I see the issue -- I was thinking of a chain of converters where values were manipulated but not Type converted. If converter1 changes the type then converter2 isn't dealing with a String any longer and thus chaining wouldn't work.
    – Dave Maple
    Jul 12 '11 at 16:35















up vote
3
down vote

favorite












This morning I had reason to try using multiple Converters on an inputText component and realized that this doesn't work.



Does anyone who why JSF only allows a single Converter per ValueHolder? It seems that using a series of Converters would be elegant in several situations.










share|improve this question


















  • 1




    Actually, I see the issue -- I was thinking of a chain of converters where values were manipulated but not Type converted. If converter1 changes the type then converter2 isn't dealing with a String any longer and thus chaining wouldn't work.
    – Dave Maple
    Jul 12 '11 at 16:35













up vote
3
down vote

favorite









up vote
3
down vote

favorite











This morning I had reason to try using multiple Converters on an inputText component and realized that this doesn't work.



Does anyone who why JSF only allows a single Converter per ValueHolder? It seems that using a series of Converters would be elegant in several situations.










share|improve this question













This morning I had reason to try using multiple Converters on an inputText component and realized that this doesn't work.



Does anyone who why JSF only allows a single Converter per ValueHolder? It seems that using a series of Converters would be elegant in several situations.







jsf jsf-2 converter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 12 '11 at 16:07









Dave Maple

4,41212554




4,41212554








  • 1




    Actually, I see the issue -- I was thinking of a chain of converters where values were manipulated but not Type converted. If converter1 changes the type then converter2 isn't dealing with a String any longer and thus chaining wouldn't work.
    – Dave Maple
    Jul 12 '11 at 16:35














  • 1




    Actually, I see the issue -- I was thinking of a chain of converters where values were manipulated but not Type converted. If converter1 changes the type then converter2 isn't dealing with a String any longer and thus chaining wouldn't work.
    – Dave Maple
    Jul 12 '11 at 16:35








1




1




Actually, I see the issue -- I was thinking of a chain of converters where values were manipulated but not Type converted. If converter1 changes the type then converter2 isn't dealing with a String any longer and thus chaining wouldn't work.
– Dave Maple
Jul 12 '11 at 16:35




Actually, I see the issue -- I was thinking of a chain of converters where values were manipulated but not Type converted. If converter1 changes the type then converter2 isn't dealing with a String any longer and thus chaining wouldn't work.
– Dave Maple
Jul 12 '11 at 16:35












1 Answer
1






active

oldest

votes

















up vote
11
down vote



accepted










In JSF, the Converter interface is designed with the following sole purpose:




Converter is an interface describing a Java class that can perform Object-to-String and String-to-Object conversions between model data objects and a String representation of those objects that is suitable for rendering.



...



getAsObject Convert the specified string value, which is associated with the specified UIComponent, into a model data object that is appropriate for being stored during the Apply Request Values phase of the request processing lifecycle.



getAsString Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.




Neither the javadoc nor the JSF spec tells about the possibility to chain converters.



Your best bet is to solve this problem at the implementation level. If you want to extend an existing converter, then you should just do so and then call super methods whenever appropriate. E.g.



public class SomeExtendedConverter extends SomeBasicConverter {

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
Object basicConvertedValue = super.getAsObject(context, component, value);

// ... manipulate more ...

return extendedConvertedValue;
}

// ...
}





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6667394%2fwhy-arent-multiple-converters-allowed-on-a-single-value-holder%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    11
    down vote



    accepted










    In JSF, the Converter interface is designed with the following sole purpose:




    Converter is an interface describing a Java class that can perform Object-to-String and String-to-Object conversions between model data objects and a String representation of those objects that is suitable for rendering.



    ...



    getAsObject Convert the specified string value, which is associated with the specified UIComponent, into a model data object that is appropriate for being stored during the Apply Request Values phase of the request processing lifecycle.



    getAsString Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.




    Neither the javadoc nor the JSF spec tells about the possibility to chain converters.



    Your best bet is to solve this problem at the implementation level. If you want to extend an existing converter, then you should just do so and then call super methods whenever appropriate. E.g.



    public class SomeExtendedConverter extends SomeBasicConverter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
    Object basicConvertedValue = super.getAsObject(context, component, value);

    // ... manipulate more ...

    return extendedConvertedValue;
    }

    // ...
    }





    share|improve this answer

























      up vote
      11
      down vote



      accepted










      In JSF, the Converter interface is designed with the following sole purpose:




      Converter is an interface describing a Java class that can perform Object-to-String and String-to-Object conversions between model data objects and a String representation of those objects that is suitable for rendering.



      ...



      getAsObject Convert the specified string value, which is associated with the specified UIComponent, into a model data object that is appropriate for being stored during the Apply Request Values phase of the request processing lifecycle.



      getAsString Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.




      Neither the javadoc nor the JSF spec tells about the possibility to chain converters.



      Your best bet is to solve this problem at the implementation level. If you want to extend an existing converter, then you should just do so and then call super methods whenever appropriate. E.g.



      public class SomeExtendedConverter extends SomeBasicConverter {

      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
      Object basicConvertedValue = super.getAsObject(context, component, value);

      // ... manipulate more ...

      return extendedConvertedValue;
      }

      // ...
      }





      share|improve this answer























        up vote
        11
        down vote



        accepted







        up vote
        11
        down vote



        accepted






        In JSF, the Converter interface is designed with the following sole purpose:




        Converter is an interface describing a Java class that can perform Object-to-String and String-to-Object conversions between model data objects and a String representation of those objects that is suitable for rendering.



        ...



        getAsObject Convert the specified string value, which is associated with the specified UIComponent, into a model data object that is appropriate for being stored during the Apply Request Values phase of the request processing lifecycle.



        getAsString Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.




        Neither the javadoc nor the JSF spec tells about the possibility to chain converters.



        Your best bet is to solve this problem at the implementation level. If you want to extend an existing converter, then you should just do so and then call super methods whenever appropriate. E.g.



        public class SomeExtendedConverter extends SomeBasicConverter {

        @Override
        public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Object basicConvertedValue = super.getAsObject(context, component, value);

        // ... manipulate more ...

        return extendedConvertedValue;
        }

        // ...
        }





        share|improve this answer












        In JSF, the Converter interface is designed with the following sole purpose:




        Converter is an interface describing a Java class that can perform Object-to-String and String-to-Object conversions between model data objects and a String representation of those objects that is suitable for rendering.



        ...



        getAsObject Convert the specified string value, which is associated with the specified UIComponent, into a model data object that is appropriate for being stored during the Apply Request Values phase of the request processing lifecycle.



        getAsString Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.




        Neither the javadoc nor the JSF spec tells about the possibility to chain converters.



        Your best bet is to solve this problem at the implementation level. If you want to extend an existing converter, then you should just do so and then call super methods whenever appropriate. E.g.



        public class SomeExtendedConverter extends SomeBasicConverter {

        @Override
        public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Object basicConvertedValue = super.getAsObject(context, component, value);

        // ... manipulate more ...

        return extendedConvertedValue;
        }

        // ...
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 12 '11 at 20:37









        BalusC

        837k29531043186




        837k29531043186






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6667394%2fwhy-arent-multiple-converters-allowed-on-a-single-value-holder%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()