Once the user successful login to the system, the system will redirect the user to the homepage. Now my problem is, if the user clicks on the view account page without login
You're too late and that is giving you the exception. Do it in a phaselistener before the render response phase.