struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Custom TextProvider -- fall-back not working?
Date Wed, 08 Jun 2011 19:17:23 GMT
This is a question that has come up before, but I've not seen it answered fully (I searched
the list first!).  Here's what I've got so far.

Implement a custom resource provider that gets searched BEFORE the action-level, interface-level,
or package-level ".properties" files, and gets its resources from the database.  If the resource
is not found, then fall-back to the normal Struts2 resolution chain of checking action, interface,
package, global / defaults.

Theory / Help:
Struts 2 supports hooking your own TextProvider implementations in by registering the bean
with a name and setting a constant in "struts.xml":

    <bean type="com.opensymphony.xwork2.TextProvider" name="myProvider" class="com.example.struts2.DBTextProvider"
scope="default" />
    <constant name="struts.xworkTextProvider" value="myProvider" />

My implementation of DBTextProvider is here:

Note that it doesn't actually DO anything on its own -- it simply calls getTextProvider().getText(...
).   I followed ActionSupport's lead by doing that.  I had planned on hooking in the custom
stuff in each implemented method, then calling the "normal" method explicitly if it's not
found.  It occurs to me that I might not need to do that explicitly if my TextProvider were
first in line of a list of alternatives.

This test-case does not work -- all of my package-level resources are ignored, and I see many
messages in my JBoss log like:
WARN  [org.apache.struts2.util.TextProviderHelper] (http- The default value
expression '' was evaluated and did not match a property.  The literal value
'' will be used.

Could someone point me in the right direction?  What's wrong with my DBTextProvider?


Roland McIntosh

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message