12 Replies Latest reply on Jul 31, 2007 5:02 PM by Pierre Raoul

    Seam Gen

    dudududu Novice

      Is there any documentation or any test case how to change seam gen?

      i.e I would like to have drop down list for codes-tables

        • 1. Re: Seam Gen
          Norman Richards Master

          We didn't really anticipate users changing the code generator on their own, so there's no real documentation for that. You'll just have to look at the code. If you do come up with an general-purpose seamgen enhancements, please consider contributing them back.

          • 2. Re: Seam Gen
            dudududu Novice

            well

            1st in the insert/update/read(table columns) I would take the columns names from the DB table column comment(it's will be much easier for different languages)

            2nd i am not sure how but some of the foriegn keys pointing on codes tables and should look like a drop down list in update/create screens
            for example status table or list of cities table..


            don't you agree?

            • 3. Re: Seam Gen
              dudududu Novice

              I'm trying to change the template to take the column comment from the DB instead of the column name

              I found the line I've to change:
              <ui:define name="label">${componentProperty.name}</ui:define>
              but what is componentProperty , how can I retrieve the comment?

              thanks!

              • 4. Re: Seam Gen
                Pierre Raoul Novice

                About your first point, I'm not sure it's the best way to get a customized label.
                The comment must remain a comment, e.g. some thing to be use in a popup window.

                I'd rather get the column name as something immutable and use it to retrieve an i18n message.

                As example you can see the patch I proposed for i18n in seam-gen, cf. http://jira.jboss.com/jira/browse/JBSEAM-1206

                • 5. Re: Seam Gen
                  dudududu Novice

                  sounds great , will it work with Seam 2beta?
                  what do u think about my 2nd point?

                  • 6. Re: Seam Gen
                    Pierre Raoul Novice

                    About point 1: it's not on the roadmap for seam 2.0.1.GA, see http://jira.jboss.com/jira/browse/JBSEAM?report=com.atlassian.jira.plugin.system.project:roadmap-panel

                    About point 2: yes some time you want dropdown list. IMO, the presence of a foreign key is not a good criterion.
                    I already customerized my version of seam-gen for enumeration: all of them are shown as dropdown list by default.
                    An other good candidate would be the embedded attribute.
                    About many-to-one association: there is no clear default choice. Each case is specific. I have no clear idea how to specify it: annotation, hibernate mapping ...?

                    • 7. Re: Seam Gen
                      dudududu Novice

                      annotiation will be good solution
                      maybe the you can define the name of the tables you want to make drop down list out of by wildcard
                      i.e %_codes -> cities_codes

                      if I want to implement such a thing , where should I look for , is it in the ant script?

                      • 8. Re: Seam Gen
                        Pierre Raoul Novice

                        I'm not sure to understand your idea. Can you explain a little more?

                        • 9. Re: Seam Gen
                          dudududu Novice

                          yes , i was talking about many-to-one associations
                          I've a table USER and the user has many columns:
                          id
                          user_name
                          pass
                          email
                          city_code

                          the city_code column has a forigen key to CITIES table
                          which has the columns:
                          code
                          name

                          in some xml file or other config file I've parameter
                          dropdown_colum_wildcard = %_code

                          now everytime the seam-gen find a column that looks like %_code (i.e. city_code) and there is a forigen key on this column it will know that it should genrete a drop down list in the create/edit screens instead of association table

                          • 10. Re: Seam Gen
                            Pierre Raoul Novice

                            why not.

                            IMO a better trick would be to use hibernate custom value types for the foreign keys. Then it will be easy to check these types in the template.


                            • 11. Re: Seam Gen
                              dudududu Novice

                              great , can u give me a tip how to implement it?

                              • 12. Re: Seam Gen
                                Pierre Raoul Novice

                                in generate-entities target, add a hbmtemplate to create some hibernate-console.cfg.xml file.

                                 <hbmtemplate filepattern="hibernate-console.cfg.xml"
                                 template="hibernatetools/hibernate-console.cfg.xml.ftl"
                                 destdir="${project.home}"
                                 />
                                
                                


                                with template
                                <?xml version="1.0" encoding="UTF-8"?>
                                <!DOCTYPE hibernate-configuration PUBLIC
                                 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
                                <hibernate-configuration>
                                 <session-factory>
                                 <#foreach entity in cfg.classMappings>
                                 <mapping class="${entity.entityName}" />
                                 </#foreach>
                                 </session-factory>
                                </hibernate-configuration>
                                


                                Then you can use the generated file to define any custom values and specify wich properties are concerned.

                                As this file will be overwritten at each run of generate-entities, may be a better way will be to create a cfg.xml file for each entity.

                                about custom value types, see http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#mapping-types-custom

                                about template: the job is done in seam-gen/view/editproperty.xhtml.ftl, viewproperty.xhtml.ftl and list.xhtml.ftl