You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephan Windmüller <st...@tu-dortmund.de> on 2014/07/31 15:43:08 UTC

Injecting custom resources

Hello,

in the documentation[0] is is stated that Tapestry supports injection 
for five types of resources: String, Locale, Logger, ComponentResources, 
and Messages.

I am wondering if it possible to extend the list with my own resource. 
What I have in mind is a custom messages resource which is aware of the 
current component/page and also has access to the current locale as well 
as another injected service. I want to use it to extend the solution 
mentioned in my earlier thread "Product-line specific component messages".

Replacing MessagesImpl directly does not seem the way to go, since this 
resource looks very hard-coded.

Regards
  Stephan

[0] http://tapestry.apache.org/injection.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Injecting custom resources

Posted by Stephan Windmüller <st...@tu-dortmund.de>.
On 01.08.2014, Thiago H de Paula Figueiredo wrote:

>> We are currently preparing an example application based on the Maven
>> archetype. I can post the link once it is available, if you are  
>> interested.
> I really, really like this solution. I had totally forgot about template  
> skinning and axis. Thanks for sharing this! :)

It has taken a while, but if anyone stumbles upon this in the archives,
here is the corresponding blog article:

http://www.kingsware.de/2014/08/19/realize-a-product-line-with-tapestry-5/

A demo project on GitHub is also available:

https://github.com/juangamnik/productlinemessages

- Stephan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Injecting custom resources

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 01 Aug 2014 09:41:18 -0300, Stephan Windmüller  
<st...@tu-dortmund.de> wrote:

> I had a look at the implementation of TapestryModule and had the feeling
> that the MasterObjectProvider only covers global objects without a
> reference to the calling component. Did I miss something?

I believe you're right. MasterObjectProvider is Tapestry-IoC level, not  
Tapestry(-core) level. For component-aware injection, you'd need to write  
a ComponentClassTransformWorker.

> What we did now is introducing a new axis (the product line) for the
> component resource locator as explained in [0]. A custom
> PageRenderRequestFilter parses the activation context and sets the
> current product line. The modified resource locator then adds the
> modified property-files to the list of parsed resources. This way we can
> add a new product-line easily just by adding files like
> "Component-productlinename(_locale).properties" which only override
> specific keys. The advantages are:
>
> - No more setting the product line in onActivate
> - Same keys in all property-files
> - Same message prefix as before, existing code does not have to be
>   changed
> - Works for both TML expressions and injected messages
> - Product lines may be added by adding a JAR file to the classpath
>
> We are currently preparing an example application based on the Maven
> archetype. I can post the link once it is available, if you are  
> interested.

I really, really like this solution. I had totally forgot about template  
skinning and axis. Thanks for sharing this! :)

> Again, thank you very much for your continued support on this mailing
> list, it is greatly appreciated!

;)

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Injecting custom resources

Posted by Stephan Windmüller <st...@tu-dortmund.de>.
On 31.07.2014, Thiago H de Paula Figueiredo wrote:

>> I am wondering if it possible to extend the list with my own resource.
> Yep! Do what Tapestry itself does: contribute ObjectProvider instances to  
> the MasterObjectProvider service. For example, injection of symbol values  
> using @Symbol is implemented by SymbolObjectProvider.

I had a look at the implementation of TapestryModule and had the feeling
that the MasterObjectProvider only covers global objects without a
reference to the calling component. Did I miss something?

>> What I have in mind is a custom messages resource which is aware of the  
>> current component/page and also has access to the current locale as well  
>> as another injected service. I want to use it to extend the solution  
>> mentioned in my earlier thread "Product-line specific component  
>> messages".
> Wasn't the solution we built enough? Why?

The solution you provided is elegant and works perfectly well on
messages specified in the TML. However, it does not affect any messages
evaluated using an injected messages object, like when performing
Messages.format(String, Object...) in a component.

What we did now is introducing a new axis (the product line) for the
component resource locator as explained in [0]. A custom
PageRenderRequestFilter parses the activation context and sets the
current product line. The modified resource locator then adds the
modified property-files to the list of parsed resources. This way we can
add a new product-line easily just by adding files like
"Component-productlinename(_locale).properties" which only override
specific keys. The advantages are:

- No more setting the product line in onActivate
- Same keys in all property-files
- Same message prefix as before, existing code does not have to be
  changed
- Works for both TML expressions and injected messages
- Product lines may be added by adding a JAR file to the classpath

We are currently preparing an example application based on the Maven
archetype. I can post the link once it is available, if you are interested.

Again, thank you very much for your continued support on this mailing
list, it is greatly appreciated!

Regards
 Stephan

[0] http://blog.tapestry5.de/index.php/2011/06/24/template-skinning/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Injecting custom resources

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 31 Jul 2014 10:43:08 -0300, Stephan Windmüller  
<st...@tu-dortmund.de> wrote:

> Hello,

Hi!

> I am wondering if it possible to extend the list with my own resource.

Yep! Do what Tapestry itself does: contribute ObjectProvider instances to  
the MasterObjectProvider service. For example, injection of symbol values  
using @Symbol is implemented by SymbolObjectProvider.

> What I have in mind is a custom messages resource which is aware of the  
> current component/page and also has access to the current locale as well  
> as another injected service. I want to use it to extend the solution  
> mentioned in my earlier thread "Product-line specific component  
> messages".

Wasn't the solution we built enough? Why?

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org