Re: Problem overriding service ValidationMessagesSource

2009-09-15 Thread P . Stavrinides
Hi Inge,

I have never tried, but looking at this code in TapestryModule, perhaps an idea 
could be to try and contribute your own update listener, see:

public ValidationMessagesSource buildValidationMessagesSource(List 
configuration,
  
UpdateListenerHub updateListenerHub,
  
@ClasspathProvider AssetFactory classpathAssetFactory,
  
ClasspathURLConverter classpathURLConverter)
{
ValidationMessagesSourceImpl service = new 
ValidationMessagesSourceImpl(configuration,

classpathAssetFactory.getRootResource(),
 
classpathURLConverter);
updateListenerHub.addUpdateListener(service);
return service;
}

see also UpdateListenerHub

So in theory when your listener could be chained with the rest of the listeners 
and detect the underlying state has changed, you would probably need to 
decorate ValidationMessagesSource or something... like I said just an untested 
idea, I ran into some slightly related issues and files this jira:
https://issues.apache.org/jira/browse/TAP5-838

It would be nice to have slightly more access to this area of the API

Kind regards,
Peter



- Original Message -
From: "Inge Solvoll" 
To: "Tapestry users" 
Sent: Wednesday, 9 September, 2009 13:51:53 GMT +02:00 Athens, Beirut, 
Bucharest, Istanbul
Subject: Problem overriding service ValidationMessagesSource

Hi!

I want to use my DB-based Messages implementation instead of the T5 property
file based one. My problem is that the getValidationMessages method of my
source is only called once, and probably cached until next server restart.
This doesn't work very good for me, as every request potentially is a new
user with a new Locale/language that should be looked up from DB. Any ideas
on how I could configure the system to do a fresh read from Messages service
every time a validation message is computed?



  public static void contributeServiceOverride(MappedConfiguration configuration, @Local final org.apache.tapestry5.ioc.Messages
messages, @Local final ValidationMessagesSource validationMessagesSource) {
configuration.add(org.apache.tapestry5.ioc.Messages.class, messages);
configuration.add(ValidationMessagesSource.class,
validationMessagesSource);
  }

The implementation of my ValidationMessagesSource:

public class CustomValidationMessagesSource implements
ValidationMessagesSource, UpdateListener {

  private final Messages messages;

  public CustomValidationMessagesSource(Messages messages) {
this.messages = messages;

  }

  public Messages getValidationMessages(Locale locale) {
return messages;
  }

  public void checkForUpdates() {
// Included to find out what this does
  }
}

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



Problem overriding service ValidationMessagesSource

2009-09-09 Thread Inge Solvoll
Hi!

I want to use my DB-based Messages implementation instead of the T5 property
file based one. My problem is that the getValidationMessages method of my
source is only called once, and probably cached until next server restart.
This doesn't work very good for me, as every request potentially is a new
user with a new Locale/language that should be looked up from DB. Any ideas
on how I could configure the system to do a fresh read from Messages service
every time a validation message is computed?



  public static void contributeServiceOverride(MappedConfiguration configuration, @Local final org.apache.tapestry5.ioc.Messages
messages, @Local final ValidationMessagesSource validationMessagesSource) {
configuration.add(org.apache.tapestry5.ioc.Messages.class, messages);
configuration.add(ValidationMessagesSource.class,
validationMessagesSource);
  }

The implementation of my ValidationMessagesSource:

public class CustomValidationMessagesSource implements
ValidationMessagesSource, UpdateListener {

  private final Messages messages;

  public CustomValidationMessagesSource(Messages messages) {
this.messages = messages;

  }

  public Messages getValidationMessages(Locale locale) {
return messages;
  }

  public void checkForUpdates() {
// Included to find out what this does
  }
}