• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1382
  • 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?
0
itnifl
Asked:
itnifl
3 Solutions
 
__geof__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

0
 
jzkiddingCommented:
This can be achieved using a4j frame work. which is a ajax enabled framework made for JSF.
0
 
zabin7Commented:
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.
Eg.
page1.jsp
<h:commandButton  action="#{getNameBean.helloAction}" value="Test" />

getNameBean.java
public String helloAction(){
  //do ur stuff
  return "test";
}

navigation rule:
<navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
      <from-outcome>test</from-outcome>
      <to-view-id>/pages/page2.jsp</to-view-id>
    </navigation-case>
<navigation-rule>

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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.
0
 
itniflAuthor Commented:
jxkidding: do you have any examples?
geof: if there might be trouble with this in IE, then maybe not.. :/
0
 
itniflAuthor Commented:
None of the solution worked for me, but I can't see no reason that it shouldn't somewhere else.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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