Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Action method calls when refreshing the JSF page  RSS feed

 
Selvakumar Kumarasamy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a test application which contains a JSF page. The page contains a command button. Button's action attribute is mapped with action method in managed bean.Inside action method I am not doing anything and just redirecting to the same page using navigation-rule configured in faces-config.xml. I deployed the application and tested the page.

This is what I observed.

scenario 1:
===========

1) Run the page.
2) Refresh the page.

Observation:
------------
Action method not called.

scenario 2:
===========

1) Run the page.
2) Click the command button.
2) Refresh the page any number of times.

Observation:
------------
For each and every time the page is refreshed Action method is called.

Can anybody tell me why it is happening.
 
Venkat Sadasivam
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF is behaving correctly. In the first scenario you are just invoking the page, so obviously action method will not called.

Whereas on the second scenario you have clicked command button, which sends a POST http request to server to invoke the associated action method. When you refresh the page, the same POST http request is send to server, hence the action method is called.

JSF is not like struts, JSF invokes action only in button/ link invocation.
 
Selvakumar Kumarasamy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. Is there any way to arrest the invocation of action method while refreshing the page?
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to try using the <redirect /> tag.

The concept is similar to the PRG pattern popularized by Struts.
 
Selvakumar Kumarasamy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even after using <redirect> tag in the navigation case, the same problem exixts.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It must be solved using the <redirect /> tag. Verify if you did the stuff right.
[ August 24, 2008: Message edited by: Bauke Scholtz ]
 
trupti pinky
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, even I am having the same problem.when i refresh the page the action method in command button has been called automatically.
I have tried </redirect> in faces-config.xml
but its not working.
if any other solution is there please post .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!