4 Replies Latest reply on Apr 6, 2009 1:05 AM by swd847

    How to handle application settings best

    germandev.net-seam.wje-online.de

      Hi!


      I want to develop an application that needs to store several application wide settings like welcome messages and headers. I'm quite new to Seam and JSF and am not that sure how to handle that best.


      My idea was to create an 'Application' - scoped session bean that has a list of settings entity beans that each consist of two strings: a key and a value.


      Might there be a possibility to access the single settings like #{myAppBean.settings['settingName']}? Alternatively I could use a getter and setter for a single setting.


      Do you think this is the best (or even a good) way to realize those settings? They need to be updateable 'on the fly' while they will only change about weekly.


      Thank you in advance!

        • 1. Re: How to handle application settings best
          gonorrhea

          If these values are not going to change very often, then you can save them in the messages_xxx.properties file and read them in as a resource bundle depending on locale (Seam supports I18N).


          Otherwise, you can store the data in a DBMS table and read it from there.  This is your best bet for on-the-fly changes (update or insert the record(s) in the table(s) and see the changes in your app immediately depending on caching/scoping of components).

          • 2. Re: How to handle application settings best
            germandev.net-seam.wje-online.de

            Thank you for your answer!



            Arbi Sookazian wrote on Apr 05, 2009 04:17:


            If these values are not going to change very often, then you can save them in the messages_xxx.properties file and read them in as a resource bundle depending on locale (Seam supports I18N).


            The problem might be that I need to change these values programatically and I think it wouldn't be so easy to realize that, would it?



            Arbi Sookazian wrote on Apr 05, 2009 04:17:


            Otherwise, you can store the data in a DBMS table and read it from there.  This is your best bet for on-the-fly changes (update or insert the record(s) in the table(s) and see the changes in your app immediately depending on caching/scoping of components).


            This is what I thought to do. Do you think my approach (see above) is a good and practicable one?


            Another question: I forgot to enable email notification when I started this topic. Is it somehow possible to enable it afterwards?

            • 3. Re: How to handle application settings best
              gonorrhea

              application scope is typically used for all sessions.  so if it's session independent data/functionality, then use application scope.  otherwise, use one of the narrower scopes (sesssion, conversation, event, etc.)


              if you go the DB table route, then create the table in your DBMS and then reverse engineer the table using seam-gen's 'seam generate-model' or equivalent.


              load your SLSB/SFSB @Startup, then inject your SLSB/SFSB as required into your other Seam components whenever that data is required.




              Finally, a related annotation is the @Startup annotation, which may be applied to any application
              or session scoped component. The @Startup annotation tells Seam to instantiate the component
              immediately, when the context begins, instead of waiting until it is first referenced by a
              client.


              you can subscribe to the mail list to get all the posts to any thread here:  My Link

              • 4. Re: How to handle application settings best
                swd847

                Something so be aware of is that application scope is not shared over a cluster, so changing it on one node will have no effect on others. From the sounds of it these settings need to be stored in a database of some kind.


                In terms of using #{myAppBean.settings['settingName']} you have a couple of options. It is possible to do #{myAppBean['settingName']} if you have myAppBean inherit from Map, then in the get method put the logic to load the setting from the database (you will want some kind of cache though as this method will get called multiple times per page view).


                I would make myAppBean event or session scoped, depending on how quickly you need the new settings to filter through to users. Session scoped will result in less DB hits and better performance, but setting changes will not be seen by users until they log off and log back in. Event scope will mean that changed settings will be updated straight away, however depending on your caching strategy will probably result in more database hits.