File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Visual Web JSF Navigation... Help!

 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application whereby content should only be visible via logging in, on login a session object with the users details is created. I want to be able to check (if statement) whether this session object is null and if so, to throw the user back to the login page. My attempt at this was to have a hidden button whose action method returns "fail". I have also set up faces-config.xml to navigate to login when the outcome is "fail". So when the JSP runs, I perform an if statement and if the session variable is empty am trying to simulate a user clicking the button by calling its action method navigateToLoginPurrlease_action() . However I get no joy, is it possible to do it this way? how can one simulate a button being clicked without a user actually clicking it (i.e a hidden button purely for navigation purposes)?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not tight couple authentication with JSF. Just use a Servlet Filter.
 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok but as am new to this is it ok to elaborate just a little bit more, maybe even going as far as "How" i user the Servlet Filter?

Would greatly appreciate any help.

PS I would still love to know even just for the sake of knowing how I could have used session objects to fulfill the use case, navigating a user to the login page if the session object is null.

 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implement javax.servlet.Filter and apply logic something like:
Simple as that.
 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,
bauke I have followed your advice, read about servlet filters and implemented the following filter:



However I get a java.lang.NullPointerException error as follows:



Is there something wrong with my code? Please help.

Thanking you in advance
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.getAttribute("SessionBean1"))
.getLoggedInUser() == null)


Assumes the existence of attribute SessionBean1, which may or may not be null. However, if SessionBean1 has not been defined, the getAttribute() itself will return null. Hence the NullPointerException.
 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim, but where does SessionBean1.java need to be defined? It is a page bean in the same package as the calling class... Sorry for inconvenience but could you please elaborate a bit further?

Thanks again
 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally managed to do this. The following is how:

Thanks all!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic