5 Replies Latest reply on Oct 1, 2009 9:56 AM by bsgcic

    seam equivalent of spring util:constant ?

    gjeudy

      Hi,


      Is there a seam equivalent of spring util:constant ? I would like to inject a constant field defined on a class as an initial value to a seam component in components.xml.


      Currently it seems like I would have to declare an application scoped object giving me access to the constant value in an EL expression. Is this the recommended solution ?

        • 1. Re: seam equivalent of spring util:constant ?
          diegocoronel

          Something like this?


          add to your components.xml



          <factory    name="senhaDigitos" 
                      scope="application"
                      auto-create="true" 
                      value="8"
           />



          • 2. Re: seam equivalent of spring util:constant ?
            gjeudy

            Yeah but that constant would come from a java class field not a literal like you posted in your example.


            value=8



            • 3. Re: seam equivalent of spring util:constant ?
              ashokcm

              Did you find a way to do this?

              • 4. Re: seam equivalent of spring util:constant ?
                bsgcic

                It seams like I got it to work ok. The following was the only way (so far) that it has worked for me.


                Constants.java


                package com.mysite.util;
                
                import java.io.Serializable;
                import org.jboss.seam.annotations.Name;
                
                @Name("constants")
                public class Constants implements Serializable
                {
                  public String getHELLO_WORLD() { return "hello world"; }
                
                }
                



                components.xml


                (In this file is a snippit of using the constant in a framework:restrictions setting within a framework:entity-query declaration.)


                <framework:restrictions>
                  <value>r.someAttribute = #{constants.HELLO_WORLD}</value>
                </framework:restrictions>
                



                If anyone has any better ideas, I'm all ears. If not, I hope the above way is of help to folks.


                • 5. Re: seam equivalent of spring util:constant ?
                  bsgcic

                  I should mention that I am not familiar with spring and have never used it. Thus, I do not know if the code that I posted is equivalent to spring util:constant or not. The way I posted appears to work for using constants within components.xml.