Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JSF Invoking a bean method when navigating away from a page

Posted on 2010-11-21
6
Medium Priority
?
1,353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Accepted Solution

by:
__geof__ earned 720 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 60 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 720 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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