6 Replies Latest reply on Oct 29, 2009 2:29 PM by dan.j.allen

    Conversion: String to Beans

    bbviana

      In a web application, we usually convert the request params from String (or String array) to Beans. All web frameworks do that.
      Is string conversion a topic of Web beans spec?


      A conversion workflow has usually 3 phases:
      1 - inspect the property type: String, Date, Number, beans
      2 - do the conversion: '1 to 1, 01/01/2009 to Date, etc
      3 - inject the converted object according the request name: person.name, person.age, etc


      Who would have do this conversion?


      Thanks.

        • 1. Re: Conversion: String to Beans
          nickarls

          e.g. JSF and converters? Or did I miss the question?

          • 2. Re: Conversion: String to Beans
            bbviana

            Yes, its about converters.

            • 3. Re: Conversion: String to Beans
              pmuir

              No, conversion is not part of the spec. Seam did include a basic converter, as does EL and JSF.


              We won't be adding it to Weld or the spec IMO.

              • 4. Re: Conversion: String to Beans
                gavin.king

                Right, Weld won't include anything that is specific to a certain web framework (not even JSF). Conversion is the responsibility of your web framework.

                • 5. Re: Conversion: String to Beans
                  cpopetz

                  I'm very happy that this is being left to the web frameworks.  Weld's web framework agnosticism is awesome.  Encoding/Decoding of web request params and management of encoding schemes (foo?x=y& vs /foo/x/y) is definitely not something I want my DI container handling.

                  • 6. Re: Conversion: String to Beans
                    dan.j.allen

                    This type of conversion is covered by JSF, and can be registered to take place automatically using view parameters, that is, if you are using JSF 2. You associate a name and EL binding with a page and each time there is a transition, the bean goes back and forth between string request parameter and object.


                    Now, would it be nice to have a declarative convertor, like bean validation is to validation? In most cases, converting to and from a string is easy. Dates come to mind as something that requires developer involvement.


                    @DatePattern("yyyy-mm-dd")
                    public Date getStartDate() { return date; }



                    That would certainly be agnostic to JSF...something Wicket could consume, for instance.


                    Either way, it isn't a JSR-299 thing.