Solved

JSF Invoking a bean method when navigating away from a page

Posted on 2010-11-21
6
1,247 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Author Comment

by:itnifl
Comment Utility
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
Comment Utility
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
Comment Utility
None of the solution worked for me, but I can't see no reason that it shouldn't somewhere else.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now