I have a problem with redirecting with JSF and pretty faces. I am quite new to this stuff and need some help as I cannot get redirect to work, like I want it to.
Basically I have this in my pretty config:
<url-mapping id="newProject">
<pattern value="/newProject/" />
<view-id value="/faces/project/newProject.xhtml" />
<action>#{projectController.initNewProject}</action>
</url-mapping>
<url-mapping id="project">
<pattern value="/project/" />
<view-id value="/faces/project/projectIdx.xhtml" />
</url-mapping>
The function initNewProject looks like this:
public String initNewProject() throws IOException {
project = this.createProject(123415, "1234578943148", "KB25");
System.out.println(project);
return "pretty:project";
}
where project is a field in the ProjectController:
@Named
@ConversationScoped
public class ProjectController implements Serializable {
private transient Project project;
...
The redirect works as I wish, as the URL changes from ../newProject/ to ../project/ and the contents of /faces/project/newProject.xhtml are displayed. But somewhen during the redirect the constructor of ProjektController is called and nulls the field project.
If I change
return "pretty:project";
to
return "/project/projectIdx.xhtml";
everything works fine. The contents of project are displayed on the webpage. However the URL does not change. It stays ../newProject/ and if the user presses F5 he creates a new project which is bad.
For some other reasons I cannot store the project in the session, so that is no option for me.
I dont want the redirect to recreate the controller as I want newProject.xhtml to display contents of the project, which was created during initNewProject
How can this be achieved?
Many thanks!
Michael