JSF Invoking a bean method when navigating away from a page

Is it possible to invoke/start a bean method when navigating away from a page in JSF 2.0? If so, how?
Who is Participating?
__geof__Connect With a Mentor Commented:
I think this code should work but onunload is know to have problem in IE
# function test(){  
#   document.getElementById('formName:buttonId').click();  
# }  
# <body onunload="test();">  
# <h:commandButton action="#{backingBean.methodName}" id="buttonId" style="display: none"/>  
# </body>

Open in new window

jzkiddingConnect With a Mentor Commented:
This can be achieved using a4j frame work. which is a ajax enabled framework made for JSF.
zabin7Connect With a Mentor Commented:
Taking into consideration that u are clicking on link or a command button to navigate from the existing page to a different page, u can call the method of the bean in the action and make the method return the navigation string.
<h:commandButton  action="#{getNameBean.helloAction}" value="Test" />

public String helloAction(){
  //do ur stuff
  return "test";

navigation rule:

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

itniflAuthor Commented:
I am using h:link to navigate away from the page. I could have use h:commandLink, but then it needs to be nested into a h:form. This takes a line of space, wich I don't have. I also had some trouble with my navigation rules when trying this, even though I have set up similar rules earlier without further trouble.
itniflAuthor Commented:
jxkidding: do you have any examples?
geof: if there might be trouble with this in IE, then maybe not.. :/
itniflAuthor Commented:
None of the solution worked for me, but I can't see no reason that it shouldn't somewhere else.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.