2

The Play! documentation indicates that @Before filters cascade to child class controllers (ref).

Let's say I have:

public class BaseController extends Controller {
    @Before(only={"show"})
    public static void check() {
        Logger.info("checking...");
    }
}

public class Users extends BaseController {
    public static void show(Long id) {

    }
}

When Users#show is called, I expect "checking..." to be displayed, but it does not. Moving the @Before filter into the Users class displays the message. Removing the only modifier also result in the message being displayed.

Why doesn't the only modifier cascade along with the @Before filter?

Rich Apodaca
  • 28,316
  • 16
  • 103
  • 129

2 Answers2

0

Instead you could make your own annotation and put it on the class.

@With(NewAnnonation.class)
public class YourClass() extends Controller { methods}

Then you can use your new annotation on the class that you want to.

public class NewAnnotation() extends Controller {
@Before( only = { "YourClass.method1", "YourClass.method2", "SomeOtherClass.method"})
public static void doSomeThingBeforeMethods() {insert code :)}
SolidALb
  • 130
  • 2
  • 10
0

I believe "only" applies to the class that declares it, in this case BaseController. When the tag is resolved, play will look for a show method in the BaseConroller.

emt14
  • 4,846
  • 7
  • 37
  • 58
  • That's what it looks like to me as well. I tried adding a "show" method to BaseController as a long shot, but the @Before filter is still ignored. So I'm still stuck. – Rich Apodaca Feb 11 '12 at 20:32