title: Redirect with JSF and prettyFaces
body: <p>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.</p>
  
  <p>Basically I have this in my pretty config:</p>
  
  <pre><code>&lt;url-mapping id="newProject"&gt;
      &lt;pattern value="/newProject/" /&gt;
      &lt;view-id value="/faces/project/newProject.xhtml" /&gt;
      &lt;action&gt;#{projectController.initNewProject}&lt;/action&gt;    
  &lt;/url-mapping&gt;
  
  &lt;url-mapping id="project"&gt;
      &lt;pattern value="/project/" /&gt;
      &lt;view-id value="/faces/project/projectIdx.xhtml" /&gt;
  &lt;/url-mapping&gt;
  </code></pre>
  
  <p>The function initNewProject looks like this:</p>
  
  <pre><code>public String initNewProject() throws IOException {
  
      project = this.createProject(123415, "1234578943148", "KB25");
  
      System.out.println(project);
  
      return "pretty:project";
  }
  </code></pre>
  
  <p>where project is a field in the ProjectController:</p>
  
  <pre><code>  @Named
    @ConversationScoped
    public class ProjectController implements Serializable {
       private transient Project project;
       ...
  </code></pre>
  
  <p>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.</p>
  
  <p>If I change</p>
  
  <pre><code>    return "pretty:project";
  </code></pre>
  
  <p>to </p>
  
  <pre><code>    return "/project/projectIdx.xhtml";
  </code></pre>
  
  <p>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.</p>
  
  <p>For some other reasons I cannot store the project in the session, so that is no option for me.</p>
  
  <p>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</p>
  
  <p>How can this be achieved?</p>
  
  <p>Many thanks!</p>
  
  <p>Michael</p>