Solved

JSF Invoking a bean method when navigating away from a page

Posted on 2010-11-21
6
1,318 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 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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 
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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

717 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