• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Spring Dependency Injection in JSF Validator

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a JSF validator and want to inject a dependency injection into it of a component,

Is this possible in a JSF Validator?

The JSF Validator code is:

[code=java]
@FacesValidator("jsfValidator")
public class JSFValidator implements Validator {


public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
.....
}
}
[/code]

And I want to inject a service "ServiceImpl" into the above class,

The validator is called from a XHTML file using:
[code=java]
<h:inputText id="display" value="#{bean.value}" >
<f:validator validatorId="jsfValidator"/>
<f:attribute name="displayName" value="#{displayName}" />
</h:inputText>
[/code]

Thanks in Advance,

Niall
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring will only do dependency injection in Spring managed beans.
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can work around this by using the spring-configured tag with the @Configurable annotation.

See the following from the reference manual.
http://static.springsource.org/spring/docs/3.1.1.RELEASE/spring-framework-reference/html/aop.html#aop-atconfigurable

I have used this for a few things before and it does work.
 
Niall Loughnane
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Configurable is used with AOP, can this also be used with JSF Validators?
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huh? AOP is aspect oriented programming it is not specific to a specific type of object.

There are different configuration options as defined in the documentation I linked but in short:

1. Put @Configurable on your JSFValidator class.
2. @Autowire in your service in your JSFValidator (Make sure the Service you are autowiring in is registered spring bean)
3. Add <context:spring-configured/> to the application context
4. Make sure spring-aop is in included in your maven dependencies.

I am not familiar with how the validator is created by JSF so no guarantees but it might work.
 
Niall Loughnane
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool, Thanks for the info, Will give it a go :)

Thanks,

Niall
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I probably should not assume you have the aspectj plugin configured in your maven. I don't have any of my projects in front of me to reference but something like below should work







 
That feels good. Thanks. Here's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic