How to redirect with parameter ?

Splash Forums PrettyFaces Users How to redirect with parameter ?

This topic contains 4 replies, has 3 voices, and was last updated by  msaleh 5 years, 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18302

    msaleh
    Participant

    hi, 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, please advise, thanks.

    #22406

    When you return “pretty:edituser”, make sure that you have set the value of #{userBean.userId} to the value you want to use in the URL. PrettyFaces will extract the value from this location (based on what you have configured in your pattern,) and build the URL accordingly.

    In summary:

    userBean.setUserId(userObj.getId());
    return "pretty:edituser"

    But I actually like the syntax that you suggested – perhaps we should consider this for the future.

    @christian? thoughts?

    #22407

    Another option would be to return something like this:

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

    @lincoln: This should work, right? I think you mentioned this on the forums some time ago.

    Actually I think we could perhaps create some builder-like approach to simplify the task of creating the correct outcome. What about something like this:

    return OutcomeBuilder.mapping("edituser").with("id", userObj.getId()).toOutcome();

    or:

    return OutcomeBuilder.mapping("edituser").param(userObj.getId()).toOutcome();

    or:

    return OutcomeBuilder.viewId("/faces/pages/users/editUser.xhtml").with("id", userObj.getId()).toOutcome();

    What do you think?

    #22408

    msaleh
    Participant

    @lincoln Baxter III, your solution sometimes doesn’t work in case of i am redirecting from two different view beans.

    think of a case when i am in UserBean and i want to redirect with Parameter to AgencyBean

    both beans are view scope.

    #22409

    msaleh
    Participant

    @lincoln Baxter III, oh thanks your solution worked even with beans with different views.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Comments are closed.