Re: Server action and redirection

Splash Forums PrettyFaces Users Server action and redirection Re: Server action and redirection


I am assuming that you are using JSF2, and that you are not using value-injection in your URL-mappings.

<url-mapping id="viewProject">
<pattern value="/admin/project/#{projectid}/view" />
<view-id value="/admin/project/view.xhtml" />

PrettyFaces needs two things in order to be able to build your URL:

1. It needs to know which url-mapping to send to

2. It needs to know what the value of #{projectId} should be

You can do this by returning the path to the Facelets view file, and adding a query-parameter with the value of projectId, like so:

return "/admin/project/steps/create.xhtml?projectId="+project.getId()+"&faces-redirect=true";

PrettyFaces will intercept that redirect and send to the proper page, as long as the view matches the view that was configured in your prettyfaces <view-id>.

Otherwise, if you are using parameter injection like below, you can simple set the value of projectId in your backing bean, and then return the ‘pretty:mappingId’

<url-mapping id="viewProject">
<pattern value="/admin/project/#{projectBean.projectId : projectid}/view" />
<view-id value="/admin/project/view.xhtml" />

public String createNewProjectInDatabase()
// create project
projectId = project.getId();
return "pretty:viewProject";

I hope this helps.