Solved

JSF Invoking a bean method when navigating away from a page

Posted on 2010-11-21
6
1,277 Views
Last Modified: 2012-05-10
Is it possible to invoke/start a bean method when navigating away from a page in JSF 2.0? If so, how?
0
Comment
Question by:itnifl
6 Comments
 
LVL 6

Accepted Solution

by:
__geof__ earned 240 total points
ID: 34186195
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
 
LVL 2

Assisted Solution

by:jzkidding
jzkidding earned 20 total points
ID: 34186855
This can be achieved using a4j frame work. which is a ajax enabled framework made for JSF.
0
 
LVL 1

Assisted Solution

by:zabin7
zabin7 earned 240 total points
ID: 34186963
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 2

Author Comment

by:itnifl
ID: 34194263
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
 
LVL 2

Author Comment

by:itnifl
ID: 34194267
jxkidding: do you have any examples?
geof: if there might be trouble with this in IE, then maybe not.. :/
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 34213974
None of the solution worked for me, but I can't see no reason that it shouldn't somewhere else.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 73
simple java question 3 56
replace a word with other 1 44
reverse digits of a number using for loop 5 45
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question