3

I'd like to know how to redirect to the same page on action call.

I have this commandButton:

<h:commandButton action="#{someBean.edit}" value="Edit" />

This is the action:

@Named
@RequestScoped
public class SomeBean {

    public String edit() {
        // some logic
        return "theSamePage?faces-redirect=true";
    }

}

But it doesn't redirect to the same page, it just refreshes it so when I try to refresh the page by pressing F5 key, the duplicate submission occurs. This can be solved, under normal circumstances, with post/redirect/get. But faces won't send the redirect when the action method returns the same viewId as the viewId of the page that the request is send from.

I use prettyfaces.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
VaclavDedik
  • 1,960
  • 4
  • 20
  • 27

2 Answers2

5
return "pretty:"; 

Is pretty much what you need.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
pseudo
  • 836
  • 1
  • 11
  • 20
0

I have done some searching and rewriting my answer:

The view id in pretty faces you can get by doing this:

      PrettyContext prettyContext = PrettyContext.newInstance((HttpServletRequest) request); 
      String viewId = prettyContext.getCurrentCalculatedViewId();

Check this for more information: https://groups.google.com/group/prettyfaces-users/browse_thread/thread/f50482709d7ec69b?pli=1

Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143