• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing argument parameters between JSF pages

 
Jay Tai
Ranch Hand
Posts: 221
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have an application where the user logs in (using j_security_check). User is taken to a welcome page where user's name is displayed as a link. When clicking that link I would like to take the user to a page where the user is able to update the credentials (password, address, etc). In this way the user only has access to the link related to that specific user's credentials. I am trying the following structure:

The welcome page (adminindex.xhtml) is:



The user backing bean:


The UpdateUser.xhtml:



The stack:



The last line of the stack suggests that a null PK value is being picked up by the FacesContext method in the backing bean. I'm confused because the userName string IS the primary key of the user table which is structured like this:



I'm sure I'm getting the concept of how to pass query parameters wrong somewhere and would appreciate any advice. THANKS!
 
Jay Tai
Ranch Hand
Posts: 221
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has now been mostly resolved.

Welcome page after login:


First there's no need for the f:param as the backing bean is Sessionscoped so should preserve the values



So repeating a FacesContext get in the selectUser method of the backing seems to set the PK value (username) to null. Why? Is it because invoking a second get message re-initializes the PK value as null?

clicking the link on the welcome page displays the remote user credentials in UpdateUser.xhtml:


Now I just need to make the form updatable allowing the user to be able to change the password. please let me know if I have misunderstood any of the concepts particularly the importance of having the bean in SessionScope. Thanks, J





 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a user is logged in, there are 2 properties set in the HttpServletRequest object that establish the user's identity. There are retrievable via the "getRemoteUser()" and "getUserPrincipal()" methods. The getRemoteUser method is actually just a shorthand. It invokeds getUserPrincipal, then extracts and returns the userId from the userPrincipal object. In both cases, these methods return null unless the user is logged in.

Thus, you can use the getRemoteUser method to extract the userid, use that to lookup any desired account properties in whatever database, LDAP directory or whatever you keep account details in, and use that data to populate the backing bean for your account edit page. No page parameters required.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!