File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes execute javascript after action? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "execute javascript after action?" Watch "execute javascript after action?" New topic

execute javascript after action?

Ronald Johnson

Joined: Jan 15, 2007
Posts: 18

how can i make sure that a piece of javascript is executed after i called an action on the server?
any ideas how to achieve this (no matter how; jsf, ajax4jsf, rich faces...)

thanks for any tips
Manuel DeAngelo

Joined: Jan 25, 2008
Posts: 13
Hi Ronald!

You could just have a variable in your form bean and set this to true in your action and in the jsp / facelet you have an

regards, Manuel
Ronald Johnson

Joined: Jan 15, 2007
Posts: 18
Hi manuel, hmm, let me clarify, i have code like this:

and I want the myFunction() to be called, but only when the action #{someBean.itemClicked} has finished executing.

i can for example not use onComplete attribute since it is just looking at the client side and not on the server side....
[ February 12, 2008: Message edited by: Ronald Johnson ]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17273

This gets back to the issue about JSF being based on HTTP and HTTP being a request/response protocol.

When you fire an Action, a request is made to the server. The request is processed as per the JSF lifecycle specs and a response is sent back to the client. The response is going to be a complete HTTP page.

So the answer is: implement an onLoad() JavaScript method. If it will be used on the same page that the request was made from but only after updating, set a page variable that the onLoad method can use to tell it's a reload.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: execute javascript after action?
It's not a secret anymore!