Tarik
Tarik

Reputation: 5031

How to call javascript from tapestry code?

I'm working with tapestry 5.2.6, and I try to call à javascript from my java code (based on some processing), This is my java code:

@Mixin
private Dialog alert;    

@Inject
private JavaScriptSupport javaScriptSupport;

 void callJavaScript() {
        alert.initializeClient(WindowStyle.GREYLIGHTING);
        javaScriptSupport.addScript("G2.alert('%s', {width:500, height:80, className:'bluelighting'});",
                "Congratulations Tarik");
    }

but I have this error:

Caused by: org.apache.tapestry5.ioc.internal.OperationException: No object of type org.apache.tapestry5.services.javascript.JavaScriptSupport is available from the Environment.

Could someone help me with that error or show me how I can open that popup from my java code ?

NB: To test the callJavaScript() function, I annotated it with @AfterRender and then my popup appears correctly after page rendering.

Upvotes: 2

Views: 1521

Answers (1)

Bob Harner
Bob Harner

Reputation: 754

Try @Environmental instead of @Inject. They both should work, but it's something to try. Technically @Environmental is more correct.

Upvotes: 0

Related Questions