Search code examples
jsf-2friendly-urlprettyfaces

Redirect with parameters in PrettyFaces


i have mapping like this:

@URLMapping(id = "edituser", pattern = "/edituser/#{ id: userBean.userId}", viewId = "/faces/pages/users/editUser.xhtml")

and i want to redirect to it from an action method, so i tried the following:

return "pretty:edituser/" + userObj.getId();

but it didn't work, it reloads current page, please advise, thanks.


Solution

  • In your case something like this should work:

    return "/faces/pages/users/editUser.xhtml?faces-redirect=true&id=" + userObj.getId();
    

    Another option would be to obtain the UserBean, set the id property and then return pretty:editust. Something like this:

    public class Whatever {
    
      @Inject
      private UserBean userBean;
    
      public String action() {
    
        // do something
    
        userBean.setUserUd( someId );
        return "pretty:edituser";
    
      }
    
    }