You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Borut Bolčina <bo...@gmail.com> on 2009/05/06 13:16:44 UTC

Injecting logger into custom validator

Hi,

I have a class which extends AbstractValidator and is contributed in
my AppModule

    public static void
contributeFieldValidatorSource(MappedConfiguration<String, Validator>
configuration, ComponentClassResolver componentClassResolver) {
        configuration.add("forbiddenusername", new
ForbiddenUsername(componentClassResolver));
    }

Searching through mailing list I found that logger can not be injected
into contribute methods, only services. So what is the way to go?

Like this?

Logger logger = LoggerFactory.getLogger(ForbiddenUsername.class);

Or did I miss something? I am using 5.0.18.

Regards,
Borut

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


Antwort: Injecting logger into custom validator

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
if you use the ObjectLocator service do instantiate your validator you 
can inject the Logger interface through your constructor:

contributeFieldValidatorSource(map... ObjectLocator locator)
{
      map.add("forbiddenusername", 
locator.autobuild(ForbiddenUserName.class)
}

another option is to inject the LoggerSource service, create a Logger for 
the 
given class manually and pass it in to the validator via the constructor:

Logger logger = loggerSource.getLogger(ForbiddenUserName.class);

new ForbiddenUserName(... ,logger)

g,
kris




Borut Bolčina <bo...@gmail.com> 
06.05.2009 13:16
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
List Tapestry User <us...@tapestry.apache.org>
Kopie

Thema
Injecting logger into custom validator







Hi,

I have a class which extends AbstractValidator and is contributed in
my AppModule

    public static void
contributeFieldValidatorSource(MappedConfiguration<String, Validator>
configuration, ComponentClassResolver componentClassResolver) {
        configuration.add("forbiddenusername", new
ForbiddenUsername(componentClassResolver));
    }

Searching through mailing list I found that logger can not be injected
into contribute methods, only services. So what is the way to go?

Like this?

Logger logger = LoggerFactory.getLogger(ForbiddenUsername.class);

Or did I miss something? I am using 5.0.18.

Regards,
Borut

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