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.

Goals:
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:
http://pastebin.com/w1StdfGM

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-0.0.0.0-8080-5) The 
default value expression 'menu.search.users' was evaluated and did not match a 
property.  The literal value 'menu.search.users' will be used.

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

Sincerely,

Roland McIntosh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to