1 2 Previous Next 19 Replies Latest reply on Jan 18, 2007 9:33 AM by zeljko_t

    seam-gen and type specific controls

      It seems to me that seam-gen generates text fields for all data types. What I was expecting was check boxes for booleans and combos for enumerations.

      Is there a way to force seam-gen to do this?

      If not, does special tag for this exists, e.g. one that will render booleans as check boxes, strings as plain text boxes etc.?

      Or this should be done manually?

      Thanks!

        • 1. Re: seam-gen and type specific controls
          gavin.king

          check boxes for booleans works.

          combos for enumerations is not really possible.

          • 2. Re: seam-gen and type specific controls

            I used "yes_no" type, which generated Boolean properties in POJOs and simple text fields in pages. Does it work for Boolean or just for boolean? Can you give me a hint where is it generated?

            I am using Seam 1.1.0.GA.

            • 3. Re: seam-gen and type specific controls
              kukeltje

              look at the ftl files, you can see how pages are generated based on types... fairly easy to adapt

              • 4. Re: seam-gen and type specific controls

                I found the right file, thanks.

                It doesn't behave as I was expecting because checkboxes are generated only for Hibernate boolean type and no other types, not even for yes_no. I think they should be generated for every type that has Boolean or boolean returned class.

                Solution will be to modify edit.xhtml.ftl by replacing

                <#elseif property.value.typeName == "boolean">

                with

                <#elseif property.value.type.returnedClass == "class java.lang.Boolean">

                Second suggestion will be to use checkboxes in both list and view templates, too.

                Should I put this in Jira?
                Seam or Hibernate Tools?
                One issue for edit and one for view/list?

                • 5. Re: seam-gen and type specific controls

                  This is probably cleaner:

                  <#elseif property.value.type.returnedClass.name == "java.lang.Boolean">



                  • 6. Re: seam-gen and type specific controls
                    maxandersen

                    using returnedClass is probably the most flexible way.

                    Having combos for enums should be possible assuming you already have the enums...but if you are doing the generation based on reverse engineering the datbase then enums are not available.

                    • 7. Re: seam-gen and type specific controls

                      I'm digging through tools to add support for parametrized types. With some luck I'll be able to generate enums.

                      Idea:

                      • create type for enums
                      • feed enum type with values using strategy
                      • detect enum type in hbm2java and generate enums

                        JDBCBinder should ask for Type instead of typeName String.

                        I already solved yes_no enums with specialized strategy. This covers like 90% of my enums.

                        When I started with seam-gen I was able to convert less than 10 tables, now I have more than 60. Composite keys are blocking point for the rest.


                      • 8. Re: seam-gen and type specific controls
                        maxandersen

                         

                        "zeljko_t" wrote:
                        I'm digging through tools to add support for parametrized types. With some luck I'll be able to generate enums.

                        Idea:
                        • create type for enums


                        are you talking enums somehow detected via reverse engineering?


                        • feed enum type with values using strategy


                        ? do not understand.


                        • detect enum type in hbm2java and generate enums


                        ok


                        JDBCBinder should ask for Type instead of typeName String.


                        huh ? What difference would that make ?


                        I already solved yes_no enums with specialized strategy. This covers like 90% of my enums.


                        please show code - much easier to understand what you are doing then ;)


                        When I started with seam-gen I was able to convert less than 10 tables, now I have more than 60. Composite keys are blocking point for the rest.


                        what stopped the 10-50 tables ?


                        • 9. Re: seam-gen and type specific controls

                           

                          "max.andersen@jboss.com" wrote:

                          are you talking enums somehow detected via reverse engineering?

                          Oh, yeah. Already done.
                          MySQL "show columns" returns types among other things. enums are returned as "enum('firstValue','secondValue',...)"
                          With some parsing I can create list of possible values.


                          • feed enum type with values using strategy


                          ? do not understand.

                          Instead of returning type name, I plan to return parametrized type instance filled with enum values.


                          JDBCBinder should ask for Type instead of typeName String.

                          huh ? What difference would that make ?

                          I can create type instance and fill it with parameters.


                          I already solved yes_no enums with specialized strategy. This covers like 90% of my enums.

                          please show code - much easier to understand what you are doing then ;)

                          I plan to put it in Jira after I'm finished, but I can also put draft version now, if you like. Basically I'm executing some MySql statements to fetch more meta data than I can get from the driver. It is similar to MySQL varchar primary key problem solution that I already sent.
                          what stopped the 10-50 tables ?

                          Missing support for composite keys in seam-gen.

                          • 10. Re: seam-gen and type specific controls

                            Correction: I have 40 tables that I can't convert, 60+ works fine.

                            • 11. Re: seam-gen and type specific controls

                              I found one problem with my idea: UserType must implement returnedClass(). In this case, it must return class of the enumeration, but it does not exist yet :(

                              Any hints?

                              • 12. Re: seam-gen and type specific controls
                                maxandersen

                                 

                                "zeljko_t" wrote:
                                "max.andersen@jboss.com" wrote:

                                are you talking enums somehow detected via reverse engineering?

                                Oh, yeah. Already done.
                                MySQL "show columns" returns types among other things. enums are returned as "enum('firstValue','secondValue',...)"
                                With some parsing I can create list of possible values.


                                ok.



                                • feed enum type with values using strategy


                                ? do not understand.

                                Instead of returning type name, I plan to return parametrized type instance filled with enum values.


                                Not possible since you can't create the type without having the enum class available....this is why reveng just gets the class name as string not the concrete type.

                                support for configuring the properties is trivial (and planned) to support by adding a Map columnToHibernateTypeProperties(...) to revengstrategy.




                                JDBCBinder should ask for Type instead of typeName String.

                                huh ? What difference would that make ?


                                • 13. Re: seam-gen and type specific controls
                                  maxandersen

                                   

                                  "zeljko_t" wrote:
                                  I found one problem with my idea: UserType must implement returnedClass(). In this case, it must return class of the enumeration, but it does not exist yet :(

                                  Any hints?


                                  I see you bumped into the fundemental problems of code generation from a database and classes ;)

                                  There are a couple of options; but the simplest solution is probably to do the beans generation first (via jdbcconfiguration), compile them and then do the seam related generation based on a jpaconfiguration.

                                  other solutions would require you to keep the enum information around to use during the seam code generation - but then you have to be carefull not to make seam gen hardly coupled to have its model built by a jdbcconfiguration.



                                  • 14. Re: seam-gen and type specific controls

                                    Now I understand some design decisions in tools much better.

                                    Additional problem is that with existing SimpleValue I can't distinguish between CustomType and enumeration, an I have to because they generate different annotations (@Type vs @Enumeration + enum definition).

                                    Are you aware of any other types that are parametrized and require special handling?

                                    When do you plan to introduce columnToHibernateTypeProperties(...)?

                                    1 2 Previous Next