title: JSF best Way to pass parameters
body: <p>i'm currently working with JSF, but since i'm a old and grouchy php-dev i always mess up with the GET-Parameters of an request. (In PHP you can access the request Paramerts whenever you want, using the <code>$_GET["paramname"]</code> Array.</p>
  
  <p>Now, i'm working on an User Managment System. (CRUD) Usually i go with a list of all available users, having options like edit / delete. The edit link is then pointing to <code>http:\\localhost\editUser.xhtml?userId=5</code> for example.</p>
  
  <p>I have also an Controller called <code>UserEditController</code> which basically holds the user entity and invokes the update. </p>
  
  <p>So, inside this Controller I'm using the <code>@PostConstruct</code> Annotation to load the user with the id 5 from the DataService and store it inside a property.</p>
  
  <p>Problem here is: Wenn entering PostConstruct-Method in the <code>APPLY_REQUEST_VALUES</code>-Phase im not able to access the request Parameter Map of Faces Context (Will return null for userId)</p>
  
  <p>Controller (simplified):</p>
  
  <pre><code>@Named
  @RequestScoped
  UserEditController{
  
  
  @Inject
  private UserDataService userDataService;
  
  private User currentUser;
  
  @PostConstruct
  public void initValues(){
      String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("userId");
  
      this.currentUser = userDataService.getUserById(id);
  }
  
  public String saveCurrentUser(){
      userDataService.updateUser(this.currentUser);
      return "userManagement"; //return to overview after saving
  }
  
  //getter and setter
  }
  </code></pre>
  
  <p>This works as intened. All the Form-Fields now are bound to user's properties like <code>#{userEditController.currentUser.forename}</code> etc.</p>
  
  <p>I now added a save button with action attribute <code>{userEditController.saveCurrentUser()}</code></p>
  
  <p>However the script then enters the <code>APPLY_REQUEST_VALUES</code>-Phase And the UserEditController's initValues is called again. </p>
  
  <ul>
  <li>this results in a nullpointer Exception, when trying to access the RequestParameterMap</li>
  <li>and obviously i dont want to reload the user BEFORE saving it :-)</li>
  </ul>
  
  <p>This sounds like a stupid question but i think i'm messing up between the PHP-Style and the JSF-Style to handle things.</p>
  
  <p>Any Help would be appreciated.</p>