struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From struts....@spamgourmet.com
Subject Re: Custom TextProvider -- fall-back not working?
Date Wed, 08 Jun 2011 19:46:05 GMT
Some more minor points on this issue, relating to the document at:
http://struts.apache.org/2.2.3/xwork-core/apidocs/com/opensymphony/xwork2/TextProvider.html

* "Implementing classes can delegate TextProviderSupport" -- clarifying the verb "delegate"
or providing an example would be really useful in this javadoc.
* "Messages will be searched in multiple resource bundles" -- It's not entirely clear that
this sentence is talking about TextProviderSupport.  It seems like it's talking about the
interface, and not an implementation of it.
* several typos:  "startinag",  "the users configured locale" should read "the user's configured
locale", "implemntation"

I'm not complaining, I'm especially appreciative that there are any docs at all, but this
particular one could use sprucing up for better readability and understanding of framework
tie-in points.  It might be nice to have some of this explanation on TextProviderFactory too:
http://struts.apache.org/2.2.3/xwork-core/apidocs/com/opensymphony/xwork2/TextProviderFactory.html

That page says: "This factory enables users to provide and correctly initialize a custom TextProvider."
It could really benefit from a statement like ".. and here's how:  Your text provider is injected
.... "


On Jun 8, 2011, at 2:17 PM, struts.rgm@spamgourmet.com wrote:

> 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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 



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


Mime
View raw message