Same problem with RequestGlobals. Comes up as null when I inject it.

Haven't tried the ApplicationStateManager yet, but in my head, the suggested
code sounds like the equivalent of the @Application state annotation, which
I already tried. Am I wrong?

On Mon, Aug 25, 2008 at 11:40 PM, Inge Solvoll <[EMAIL PROTECTED]>wrote:

> Ok, thanks, I'll try that! I already tried the following in my class that
> extends AbstractMessages:
>
> @Inject
> private HttpServletRequest request;
>
> @ApplicationState
> private User user;
>
> Which didn't work, both were null. But what your saying is that these
> objects are not possible to inject in this scope, but RequestGlobals is, so
> the following will work?
>
> @Inject
> private RequestGlobals requestGlobals
>
> Regards
> Inge
>
>
> On Mon, Aug 25, 2008 at 3:57 PM, Hannes Heijkenskjöld <
> [EMAIL PROTECTED]> wrote:
>
>> Hi Inge,
>>
>> glad to have been able to help you!
>>
>> For your current problem, I can see two immediate solutions.
>>
>> 1. Store your user object as an ASO and inject ApplicationStateManager
>> into your Messages implementation. Get the user object instance by calling
>> applicationStateManager.get(UserObject.class).
>>
>> 2. Inject RequestGlobals in your Messages implementation. Then you can get
>> the request by calling requestGlobals.getHTTPServletRequest().
>>
>> I hope this helps
>>
>> /Hannes
>>
>> Inge Solvoll skrev:
>>
>>  Hi, Hannes!
>>>
>>> I tried your implementation, and it worked right away, I just returned
>>> the
>>> value "TESTING TESTING" from my DbMessages class that extends Abstract
>>> Messages.
>>>
>>> But, what I need is for the valueForKey(String key) method to be aware of
>>> the languageId/customerId of the currently logged in user. In all my
>>> other
>>> pages, I get this through injecting the request and getting my user
>>> object
>>> from HttpSession. Alternatively this can be moved to an ASO, but I
>>> haven't
>>> taken the time to do that yet.
>>>
>>> I've tried injecting HttpServletRequest and ApplicationState on all the
>>> classes listed in the implementation from Hannes, but none of them work
>>> (only null values). How can I make information from the current user
>>> session
>>> available to my AbstractMessages implementation?
>>>
>>> Regards
>>>
>>> Inge
>>>
>>> On Wed, Apr 16, 2008 at 10:22 AM, Hannes Heijkenskjöld <
>>> [EMAIL PROTECTED]> wrote:
>>>
>>>  Great!
>>>>
>>>> Glad I could help you. :-)
>>>>
>>>> /Hannes
>>>>
>>>> Michael Capper skrev:
>>>>
>>>>  Thanks Hannes!
>>>>
>>>>> I tried the route with the Decorator once, and ended up having to write
>>>>> some
>>>>> java-code into the interceptor via the BodyBuilder .... 'twas not nice.
>>>>>
>>>>> Your example worked great, i only had to pass some more Services
>>>>> (AssetSource to get the URLs, my ProjectContextProvider to get the
>>>>> ResourceBundles for my text) into the build-Method in AppModule, then i
>>>>> could return the value for a Message-Key from the bundles, or if not
>>>>> existant, from the fallbackMessages.
>>>>>
>>>>> Cheers,
>>>>> Mike
>>>>>
>>>>>
>>>>> Hannes Heijkenskjöld wrote:
>>>>>
>>>>>  Hi
>>>>>>
>>>>>> I have recently wondered about the same, and have now built something
>>>>>> that after much trial and error now works.
>>>>>>
>>>>>> Basically, I have created a Messages implementation that wraps both a
>>>>>> tapestry Messages object and our own database messages. If a message
>>>>>> is not
>>>>>> found in our database, the default Messages object is queried.
>>>>>>
>>>>>> To get Tapestry to use my Messages implementation i had to decorate
>>>>>> the
>>>>>> ComponentMessagesSource (and ValidationMessagesSource), since it is
>>>>>> not
>>>>>> possible to replace the one in Tapestry. I think I read about
>>>>>> decorating
>>>>>> services here:
>>>>>> http://tapestry.apache.org/tapestry5/tapestry-ioc/decorator.html and
>>>>>> on
>>>>>> the mailing list.
>>>>>>
>>>>>> My messages source service doesn't implement the
>>>>>> ComponentMessagesSource
>>>>>> interface. I use an interception object for that. Hopefully you can
>>>>>> understand how it works from my example code below:
>>>>>>
>>>>>> public class CommonsMessages extends AbstractMessages {
>>>>>>
>>>>>>    private Messages fallbackMessages;
>>>>>>
>>>>>>    protected String valueForKey(final key) {
>>>>>>       ... logic to get key from db, use fallbackMessages as
>>>>>> fallback...
>>>>>>    }
>>>>>>
>>>>>> }
>>>>>>
>>>>>> -----
>>>>>>
>>>>>> public class CommonsMessagesSource {
>>>>>>
>>>>>>    public Messages getMessages(Locale locale, Messages
>>>>>> fallbackMessages)
>>>>>> {
>>>>>>       ... code that creates a CommonsMessages object, with
>>>>>> fallbackMessages ...
>>>>>>    }
>>>>>> }
>>>>>>
>>>>>> ----
>>>>>>
>>>>>> // This is the decorating class
>>>>>> public class CommonsComponentMessagesSourceInterceptor implements
>>>>>>    ComponentMessagesSource {
>>>>>>
>>>>>>    private final CommonsMessagesSource service;
>>>>>>    private final ComponentMessagesSource delegate;
>>>>>>
>>>>>>    public CommonsComponentMessagesSourceInterceptor
>>>>>>        (CommonsMessagesSource service, ComponentMessagesSource
>>>>>> delegate)
>>>>>>    {
>>>>>>        this.service = service;
>>>>>>        this.delegate = delegate;
>>>>>>    }
>>>>>>
>>>>>>    public Messages getMessages(ComponentModel componentModel, Locale
>>>>>> locale) {
>>>>>>
>>>>>>        return service.getMessages(locale,
>>>>>>            delegate.getMessages(componentModel, locale));
>>>>>>    }
>>>>>>
>>>>>>    // Not sure about how I should handle this one
>>>>>>    public void addInvalidationListener(
>>>>>>        InvalidationListener invalidationlistener) {
>>>>>>        delegate.addInvalidationListener(invalidationlistener);
>>>>>>    }
>>>>>> }
>>>>>>
>>>>>> ---
>>>>>>
>>>>>> In AppModule.java:
>>>>>>
>>>>>>    // Method for instantiating and configuring the custom messages
>>>>>> source
>>>>>>    public static CommonsMessagesSource buildCommonsMessagesSource()
>>>>>>    {
>>>>>>        CommonsMessagesSource messagesSource = new
>>>>>> CommonsMessagesSource();
>>>>>>        return messagesSource;
>>>>>>    }
>>>>>>
>>>>>>    // Method that decorates the default MessagesSource using the
>>>>>> interceptor class
>>>>>>    @Match("ComponentMessagesSource")
>>>>>>    public static ComponentMessagesSource
>>>>>> decorateComponentMessagesSource
>>>>>>         (Object delegate, CommonsMessagesSource service)
>>>>>>     {
>>>>>>         return new CommonsComponentMessagesSourceInterceptor(service,
>>>>>> (ComponentMessagesSource)delegate);
>>>>>>     }
>>>>>>
>>>>>> This is how I got it to work, there may be other ways ofcourse. There
>>>>>> might even be better ways :-)
>>>>>>
>>>>>> Cheers,
>>>>>> /Hannes
>>>>>>
>>>>>> Michael Capper skrev:
>>>>>>
>>>>>>  Summary: How do I include additional localization-key/values-pairs in
>>>>>>> my
>>>>>>> global messages-catalog, originating from some app_<lang>.properties
>>>>>>> or
>>>>>>> from
>>>>>>> a database?
>>>>>>>
>>>>>>> Hi,
>>>>>>> I'd like to extend the Hash-Table containing the message-keys and
>>>>>>> message-values used in my app. The app_en.properties provides the
>>>>>>> basic
>>>>>>> global localization data, but I need even more data, which is spead
>>>>>>> about
>>>>>>> in
>>>>>>> other .properties-files or even in a Database. What I'd like to do
>>>>>>> would
>>>>>>> be
>>>>>>> to read in the data somewhere, and pass it on to the Messages(or
>>>>>>> ResourceBundle) somehow, so when I @Inject the Messages into a
>>>>>>> page/component or use the 'message:' binding, the extra localization
>>>>>>> is
>>>>>>> available at a root level.
>>>>>>>
>>>>>>> Thanks for any help or pointers,
>>>>>>> Mike
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>  ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>>>
>>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>

Reply via email to