VaclavDedik
VaclavDedik

Reputation: 1980

How to redirect back to the same page using PrettyFaces?

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.

Upvotes: 3

Views: 1250

Answers (2)

pseudo
pseudo

Reputation: 848

return "pretty:"; 

Is pretty much what you need.

Upvotes: 5

Paulius Matulionis
Paulius Matulionis

Reputation: 23415

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

Upvotes: 0

Related Questions