can I read values from a properties file in faces-config.xml file?

227 views Asked by At

In my Xpages app I would like to compute a value in the faces-config.xml by reading a value from a Notes document. Since it is an application configuration type of document and therefor the only document I think a @DBLookup function would do e.g.:

@DbLookup(@DbName(),"Profile View","Profile Document","debug","[FAILSILENT]");

However since I have placed all references to view design elements in a properties file so I can update them in 1 location instead of hard-coded references across my application I would also would avoid using a hard-coded reference in the @DbLookup function.

Normally I would get the view by collecting the value with a key (vw_ProfileDoc) as followed:

var viewName = datasources["vw_ProfileDoc"];

The datasources resource is defined on my XPage level by declaring it as a variable to a resources bundle e.g.:

<xp:bundle src="/datasources.properties" var="datasources"></xp:bundle>

So it becomes available when loading the XPage.

If I would try in the faces-config.xml something like:

<managed-property>
      <property-name>debug</property-name>
      <value>#{javascript:var vw = datasources["vw_ProfileDoc"];@DbLookup(@DbName(),vw,"ProfileDoc","debug","[FAILSILENT]");}</value>
      <property-class>java.lang.Boolean</property-class>
    </managed-property>

I will get a 404 error most likely because the datasource variable is not set.

Is there anyway to read the datasources.properties file from the faces-config.xml file?

2

There are 2 answers

4
Knut Herrmann On

I use database's Resources/Files for such use cases. Create a file "settings.properties" with settings like

debug = true
whatever = abc

You can access the values easily from Java code with

        ResourceBundle bundle = ExtLibUtil.getXspContext().bundle("settings"); 
        if (bundle != null) {
            boolean isDebug = "true".equals(bundle.getString("debug"));
            String whatever = bundle.getString("whatever");
            ...
2
John Dalsgaard On

Not sure why you want to do that in faces-config.xml? And from what I know you cannot do anything dynamic in that file!

You can use Knut's suggestion which will work fine.

What I do is have some sort of config document in the database that I can use to set a flag (or more flags, actually)...

Then in my app I have an app-scoped bean that will read this information on startup (and can have logic to reset or reread or whatever you need to "discover" if a setting has just been changed). Then inside my XPages and in Java code I just ask the property of the app-scoped bean if debug is set or not - and then do whatever I have to based on that. Easy and very clean :-)

I have this in place for exactly the case you mentioned in a comment to Knut's answer where I can increase logging on demand from within the application directly in a production environment.

/John