3

Got a really simple question on JSF 2 navigation mechanism:

I have two views, call it 'ProductEdit' and 'ProductList', with request scoped backing beans (I don't think this is relevant anyways). I have the following lines in the 'ProductEdit' view

            <h:commandLink action="#{product.update('')}">
                <h:outputText value="Update And Return"></h:outputText>
                <f:param name="pageNo" value="#{productlist.pageNo}" />
            </h:commandLink>

When a user clicks on the 'Update and Return' link in the 'ProductEdit' view, the specified action is performed(pretty standard in JSF) and outcome of it is the 'ProductList' view and the user is directed to the page no problem. However the URL of the page remains 'ProductEdit' in my browser although the view that is displayed is the 'ProductList' view.

Surely the URL must be updated, what am I doing wrong?

Hoping BalusC is online now!.

ManiP
  • 713
  • 2
  • 8
  • 19

1 Answers1

4

Sorry for my previous answer, you can add "?faces-redirect=true"at then end of your link returned by your action. Or, if you are going to use PrimeFaces, just set parameter ajax to false.

EDIT

public String update() {
    return "index?faces-redirect=true";
}

I will borrow one of the BalusCs answers - here you can see few ways how to do it.

Community
  • 1
  • 1
Petr Mensik
  • 26,874
  • 17
  • 90
  • 115
  • But that wouldn't perform the action product.update('') which I need to run! – ManiP Aug 07 '12 at 13:34
  • Where do I add that to? ie where does "?faces-redirect=true" get appended, to the view name? Not using PF. – ManiP Aug 07 '12 at 13:39
  • No, in the update method. This method has to return String (or null or be void which is the same) which will redirect you somewhere (let's say "index"), so just append it here - return "index?faces-redirect=true" – Petr Mensik Aug 07 '12 at 13:40
  • Would this work : action="#{product.update('')}?faces-redirect=true" ? – ManiP Aug 07 '12 at 13:43
  • @PetrMensik you should have added that example from the beginning. – Luiggi Mendoza Aug 07 '12 at 13:48
  • The URL is now correctly reflected, however the 'pageNo' is not being passed through now! – ManiP Aug 07 '12 at 14:00