3 Replies Latest reply on Feb 27, 2009 1:10 AM by Norman Richards

    Access to web.xml <context-param> values

    Valerie Griffin Newbie
      I need to access <context-param> values defined in web.xml from my Seam application. In this case, I need to use a couple of items when the application is initialized. The easy part was creating the class at application startup:

      @Name("applicationPrefs")
      @Scope(ScopeType.APPLICATION)
      @Startup
      public class ApplicationPrefs {
      }

      Finding the properties I cared about was harder. I knew they would be buried inside the ApplicationContext so I included the code:

                Context ctx = Contexts.getApplicationContext();
                String[] ctxNames = ctx.getNames();

      and displayed the names and their associated values. I figured out that I could get the properties by adding:

                HashMap<Object, Object> seamProps =
                     (HashMap<Object, Object>) ctx.get("org.jboss.seam.properties");

      The keys are all Strings and the values are all instances of org.jboss.seam.util.Conversions$FlatPropertyValue so the value canreally be pretty much anything. all we care about are a couple of String values, so we can convert using only the toString method.

      I'm fetching my values using:

              String configFilePath = seamProps.get("configFile").toString();

      It's great how easily I can get the info I want, but I'd prefer to use a standard way to get the properties instead of digging around for something that may not be standard that I figured out by reverse-engineering.

      Is there a cleaner way to get this info? Is it documented anywhere? How would I convert things that aren't Strings?