• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1431
  • Last Modified:

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?
3 Solutions
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

This can be achieved using a4j frame work. which is a ajax enabled framework made for JSF.
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now