1 2 3 Previous Next 33 Replies Latest reply on Nov 10, 2010 2:30 PM by Todd Morrison

    15 gotchas in seam

    Dean Hiller Expert

      I am tired of running into so many gotchas in seam so I am going to start a list here and keep it going so I can refer back to it.  hopefully it helps others as well.  (yes, these are personal opinions).



      1. Do NOT use s:convertEntity if you are using a Session action bean and a form.  See http://seamframework.org/Documentation/DropdownBoxesWithEntitiesAndPageScope for more info.  OR do NOT use pulldowns unless you are in a conversation is the other way to go.

      2. Add required=false to every @In @Out attribute (or your clustering will break since there is no seam session at time of clustering)

      3. Do NOT use entityMgr.merge as it gets you into trouble time after time.  Use if(bean.getId != null) entityMgr.persist(bean) instead

      4. DO lookup your bean at the start of every conversation or if in a session with entityMgr.find(Bean.class, bean.getId()) so you don't end up in trouble.

      5. Do make sure that s:button is in an h:form or clustering for just that button will NOT work but it will work with clustering off

      6. Please vote on https://jira.jboss.org/jira/browse/JBSEAM-4460 as the conversation is already in progress error is very annoying.  Most of the time, we don't care that a conversation is in progress and want to end the previous conversation if one exists.

      7. DO make sure you have a good grasp on proxies vs. instances in hibernate and when debugging pay very good attention as seam is sometimes comparing a proxy to an instance and failing validation because of that :(. 



      This is the list off the top of my head.  I will continue to post as I run into the previous issues I have run into before.  I know there are around 15 gotchas in seam that you have to be careful of.


      Seam does rock!!  just has some issues that I want to keep track of.  Feel free to add your list here as well.




        • 1. Re: 15 gotchas in seam
          Francisco Jose Peredo Noguez Master

          How about:



          1. Do not use EAR/EJBs if you want ZeroTurnaround, use WAR/POJOs. Read more

          2. Do not use JPA if you want full ZeroTurnaround

          3. Do not use JBossAs 4.x if you want your application to do cold restarts fast during development (for example if you decided to use JPA) (Don't know if 5.x starts faster, if it does not, revert to plain Tomcat)

          4. Do not use EmbeddedJBoss if you want your tests to run fast (just delete the jboss .jars from your test project and and use Spring to get to you datasource)

          5. Do not use JSF/Richfaces 3.x without http compression enabled because it generates a huge amount of XHML that will take a lot of time to download and your users will get angry, enable tomcat http compression, if your admin refuses to let you do it, use a filter

          6. Do not validate simple stuff (numeric fields, regular expressions, dates, simple comparisions between fields, etc) using seam/jsf/richfaces validation, it is very slow, and your users will not like it, use jQuery, only use seam/jsf/richfaces validation for complex business logic stuff.

          7. Do not trust seam-gen CRUD, the code it generates is wrong.

          8. If you are using Richfaces, always work with the global queue enabled it will save you lots of could not acquire lock on @Synchronized component headaches

          9. If you are  Richfaces global queue do not believe it is going to solve all your concurrency problems, if you need stability fast, use ConfigurableSynchronizationInterceptor with a big default value (around 1 minute). Read more



          And those are only the ones I can think from the top of my head...

          • 2. Re: 15 gotchas in seam
            Dean Hiller Expert

            great additions.  I just ran into a new one.


            Do NOT bother using rich:comboBox with s:selectItems s:convertEntity and s:convertEnum...you are wasting your time, wait for JIRA issue.... https://jira.jboss.org/jira/browse/RF-5046 which should support it(vote on the issue too!!!)  I would have used this widget for every pulldown if it worked better.

            • 3. Re: 15 gotchas in seam
              guy bashan Apprentice

              Nice things, I especially like Francisco Peredo list.
              I think maybe this list should have a better place... (maybe sticky).

              • 4. Re: 15 gotchas in seam
                Trelieux Einagen Newbie

                Thanks for the list guys, others and myself really appreciate it!  And Franciso I really like your quote where or from whom is it from?

                • 5. Re: 15 gotchas in seam
                  Arbi Sookazian Master

                  definitely sticky this thread!

                  • 6. Re: 15 gotchas in seam
                    David Haynes Newbie

                    Nelson Mandella in his inaugural speech 1994.

                    • 7. Re: 15 gotchas in seam
                      Jaime Martin Apprentice

                      Really good gotchas lists Dean, and Francisco!! Thread should be sticky and lists added to the knowledge base.

                      • 8. Re: 15 gotchas in seam
                        Shervin Asgari Master

                        Here is some of mine:




                        1. Force IE8 to run in IE7 mode because of bug in JSF/Seam/Facelets



                        <page view-id="*">
                            <header name="X-UA-Compatible">IE=EmulateIE7</header>



                        2. Remember that @WebRemote and jpdl.xml does not use your custom defined Message Bundle, it uses the default one even if you have configured to use custom in faces-config.xml. See here



                        3. Links of files using s:link inside seam pdf if you download and open the pdf in pdf viewer (ie adobe reader), then the servlet path will be replaced with file:///project/. You have to hardcode the a href with the servlet path together with the slink.


                        <s:link action="#{fileHandler.downloadById()}" value="#{file.name}" propagation="none">
                              <f:param  name="fileId" value="#{file.id}"/>
                        </s:link>
                         <a href="#{servletPath.path}?fileId=#{file.id}&amp;actionMethod=#{path.replace('/','')}%2Fstatus%2Fstatus_pdf.xhtml%3AfileHandler.downloadById()&amp;" >download</a>



                        Where servletPath.path returns correct url to your server ie: http://localhost:8080/whatever


                        4. Hibernate does not care about ordering of your entity beans for creation of tables. So if you have create-drop in your persistence.xml and something in import.sql that requires ordering of rows in table to be correct, then you must have created the table before and not let hibernate create it for you. Link.

                        • 9. Re: 15 gotchas in seam
                          Jean Luc Apprentice

                          Hi Dean,


                          Thanks for compiling this, I did run into some of them as well. I have some questions, though, as some of the statements require them.



                          Add required=false to every @In @Out attribute (or your clustering will break since there is no seam session at time of clustering)


                          Can you be more specific? What do you mean by the time of clustering? When the server or the application are being started up? Or during a failover?



                          Do NOT use entityMgr.merge as it gets you into trouble time after time.  Use if(bean.getId != null) entityMgr.persist(bean) instead


                          Again, can you be more specific? I've been using merge() for many months and have had no problems once I understood how it works (which, granted, is not intuitive: the old entity is read, non-transient fields are copied into it from the updated entity then the old entity is saved).



                          Do make sure that s:button is in an h:form or clustering for just that button will NOT work but it will work with clustering off


                          What do you mean clustering for the button? Load balancing of the call to the underlying session bean? The failover of the same call?



                          • 10. Re: 15 gotchas in seam
                            Dean Hiller Expert

                            Add required=false to every @In @Out attribute (or your clustering will break since there is no seam session at time of clustering)

                            if you set yours up for clustering, seam luckily replicates the session AFTER the page loads(unlike some impls which if session replication fails, your page does not load).  anyways, if you have the default which is true, session replication fails on that bean constantly(stateful beans of course...not sure if it matters or not on stateless ones...it shouldn't but don't know for sure until I see it with my own eyes)



                            Do make sure that s:button is in an h:form or clustering for just that button will NOT work but it will work with clustering off

                            I had an h:commandButton and a s:button on one page and we would fail one node, click the h:commandButton and it failed over successfully.  The same scenario and clicking s:button however fails in a clustered environment.



                            Do NOT use entityMgr.merge as it gets you into trouble time after time. Use if(bean.getId != null) entityMgr.persist(bean) instead

                            We have had multiple situations with merge screwing things up.  One of them was this...
                            http://seamframework.org/Community/StaleStateExceptionAfterUpdateSuccessAndTxIsDone


                            Also, this may be a good post for some other people(more a hibernate issue though I think as it would be nice if hibernate filed in the top level exception message with the details of eery getNextSQLException for you....
                            http://www.seamframework.org/102758.lace


                            We had other merge problems as well we ran into where after a merge you have a proxy but the data model(ie. someOtherBean.getchild() had the instance(and these guys are not equal!!!!)  Later, if you have a list of things and the selected one is a proxy and the one in the list of items is an instance, you get dang value is not valid errors.  After throwing merge away, we have never had any problems since then!!!  I am sure eventually you will run into a situation ;).


                            • 11. Re: 15 gotchas in seam
                              Trelieux Einagen Newbie

                              This post should be a sticky post.

                              • 12. Re: 15 gotchas in seam
                                Arbi Sookazian Master

                                em.merge() is a crude operation that is not recommended (or even necessary) if you are using SMPC and HMF and as a result the PC does not close during the LRC.  You should only merge() entities into the PC if they are detached.  They do not become detached if you use SMPC and Hibernate manual flush.  Read SiA for more on this...


                                sticky this thread!


                                oh, and what about (ab)use of (or lack thereof?) of @BypassInterceptors.  Some of these comments will become historical/irrelevant for Seam 3 with the injection of Weld as the new Seam core (e.g. no more interceptors and no more contextual variables).

                                • 13. Re: 15 gotchas in seam
                                  Arbi Sookazian Master

                                  Don't forget (ab)use of the rendered attribute in JSF tags.  DAllen covers this here:


                                  http://www.jsfcentral.com/articles/speed_up_your_jsf_app_1.html

                                  • 14. Re: 15 gotchas in seam
                                    Stuart Douglas Master

                                    I find the biggest problem is invoking an action no matter what validation failures occur without loosing all the values a user has entered, e.g. deleting a row in a data table but keeping the values for all the other rows. Solution is here.

                                    1 2 3 Previous Next