Injection fails in rewrite processor. Injected components are always null

Splash Forums PrettyFaces Users Injection fails in rewrite processor. Injected components are always null

This topic contains 2 replies, has 2 voices, and was last updated by  Christian Kaltepoth 9 years, 10 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #18197


    I’m having trouble using injection inside of a pretty faces rewrite processor and could use some help. Whenever the component I am trying to inject is always null. I’m using the following:


    cdi 1.0

    jsf 2.1.2


    <rewrite match="^/redirect/myRedirect"
    processor="com.mypackage.MyRewriteProcessor" redirect="302" />

    public class MyRewriteProcessor implements Processor {

    private MyService myService;

    public String processInbound(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
    RewriteRule rewriteRule, String s) {

    public class MyService {

    public void doSomething(){...}

    myService.doSomething() always produces a NPE in the processor. Am I approaching this from the wrong angle, or is there some issue with this not happening in the correct lifecycle phase?

    Any guidance is appreciated.



    The problem is that PrettyFaces creates an instance of the rewrite processor itself. So CDI isn’t involved here. Therefore @Inject won’t have any effect. Your only option is to manually obtain the BeanManager and lookup the service for yourself. I did something similar in the past and created a simple helper class for this. Unfortunately I currently don’t have access to the code. But I will post it later today as soon as I’m in the office.


    I think the easiest way for you is to use some library for this. Deltaspike for example contains a helper class called BeanProvider that can be used to manually look up beans like this:

    MyService myService = BeanProvider.getContextualReference(MyService.class, false);

    To include Deltaspike in your project just add this to your pom:


    I think other libraries like Seam Solder and MyFaces CODI provide similar functionality.

Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.