6 Replies Latest reply on Aug 30, 2007 2:58 AM by anescu

    Can I define some "constants" in the components.xml?

      Hello,

      So, I would like to set some parameters that will be used to configure a module, like an email server, jms context, etc.

      The class that does the actual processing is not a Seam component, and further more, is being called from multiple Seam components. I know I could define the parameters for each Seam component, but I want to know if is a way I can define them globally (can this be done with "factory"?), and most important how do I retrieve the values inside a Seam component?

      Does this work?

      <factory name="providerUrl" value="localhost:1099"/>


      And is yes, how do you retrieve the value in a Seam component?
      Does this code work?

      @In
      private String providerUrl


        • 1. Re: Can I define some
          matt.drees

          You probably want

          <factory name="providerUrl" value="localhost:1099" scope="stateless" auto-create="true"/>
          


          The auto-create means you can use @In instead of @In(create=true).
          You can specify a different scope if you want.

          • 2. Re: Can I define some

            I want something like "application scope". Just a damn constant, the same value for everyone.

            I read the reference for Seam, I saw the factory examples, but I did not find yet any example on how to actually read the values in code. Probably there are, somewhere :).

            I'll see if I can get my code to work...

            • 3. Re: Can I define some
              fernando_jmt

              I have somethig like this:

              
               <component name="sysConfig" auto-create="true" class="com.myapp.SystemConfig" scope="APPLICATION">
               <property name="rowsPerPage">5</property>
               <property name="fileUrl">whateverpath</property>
               </component>
              
              



              
              @In
              SystemConfig sysConfig;
              
              


              • 4. Re: Can I define some
                matt.drees

                 

                "anescu" wrote:
                I want something like "application scope". Just a damn constant, the same value for everyone.


                Stateless will do that, too. Stateless means that it doesn't get stored in a scope, so any time something asks for that variable (injection, el, whatever), it will re-evaluate the value expression in the < factory >. Which in your case is a constant.

                And yeah, just use @In. It's all the same kind of stuff. You can inject any kind of contextual variable.

                • 5. Re: Can I define some
                  stu2

                  Btw take a look at the wiki example. There's a pretty nice example of doing exactly this.

                  • 6. Re: Can I define some

                    Thanks guys,

                    I made it work. For now just some String values, but I will probably transform them into a "config" class.