Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Template constraints #45

Closed
hideki22 opened this issue Oct 17, 2017 · 6 comments
Closed

Problem with Template constraints #45

hideki22 opened this issue Oct 17, 2017 · 6 comments

Comments

@hideki22
Copy link

Hello,

Im using play 2.6.5 and deadbolt 2.6.1 java.

Im trying to add @subjectPresentOr() {}{} but dont work.

im add the import

@import be.objectify.deadbolt.java.views.html.di.{subjectPresent, subjectPresentOr}

but all time say me

Compilation error
not found: value subjectPresentOr

https://deadbolt-java.readme.io/docs/template-constraints

What are doing wrong?

Thanks.

@schaloner
Copy link
Collaborator

I need to update the documentation, thanks for bringing this to my attention.

In the meantime, this should work

@this(subjectPresentOr: be.objectify.deadbolt.java.views.html.di.subjectPresentOr)

because constraints are now injected into templates (Play 2.6 removed the global state that templates previously relied on). You can see it used in a test here

@hideki22
Copy link
Author

hideki22 commented Oct 17, 2017

Ok, I try but another error,

non-static method render(be.objectify.deadbolt.java.DeadboltHandler,play.data.Form<dto.security.UserDto>) cannot be referenced from a static context

I think it was because i use @this to inyect.

@this(subjectNotPresent: be.objectify.deadbolt.java.views.html.di.subjectNotPresent)
@(deadboltHandler: be.objectify.deadbolt.java.DeadboltHandler, form: play.data.Form[dto.security.UserDto])

In the Controller, I use inyector,

public Result loginForm () {
        return ok(views.html.login.render(handler, formFactory.form(UserDto.class)));
    }

And inyect the handler in contructor,

@Inject
    public UsersController(UserDao userDao, FormFactory formFactory, @HandlerQualifiers.MainHandler final DeadboltHandler handler) {
        this.userDao = userDao;
        this.formFactory = formFactory;
        this.handler = handler;
    }

If I delete @this, this error dissapear, but dont work.

Thanks.

@schaloner
Copy link
Collaborator

@this(...) is used inside Deadbolt's templates because they have required Deadbolt components injected into them.

I think the problem is this:
non-static method xxx referenced from a static context

I think what's happening, without seeing your code, is that you're not injecting your own components into your controllers. Take a look at this guide to see how to do this.

@hideki22
Copy link
Author

Yes, this is the problem... I forgot inyect the view. Now work perfect.

Thank you so much.

@schaloner
Copy link
Collaborator

Thanks - I'll update the docs as soon as I have chance.

@bharal
Copy link

bharal commented Mar 20, 2018

Two items:
@this(subjectPresent: be.objectify.deadbolt.java.views.html.di.subjectPresent, subjectPresentOr: be.objectify.deadbolt.java.views.html.di.subjectPresentOr)

(I don't see this in the doc)

This shows how to have two items, as opposed to just one. From here on (three, four items) it's self-explanatory.

Actually, it's interesting how so often documentation shows how to do something with ONE item, or with TWO items, but never both, when really both are needed. But that's just a pet peeve of mine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants