users@glassfish.java.net

RE: problem with _at_SessionScope annotation

From: Martin Gainty <mgainty_at_hotmail.com>
Date: Wed, 7 Apr 2010 18:34:30 -0400

are you activating the mutator for userName?
usually onSubmit or onClick or onChange will activate the mutator for userName with something like #{userManager.setUserName('fubar')}"

to set the userName Value

 

glassfish contains a sample called UniversalClient which has accessors and mutators for all the attributes of the bean (including userName)


Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité


Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.



 

> Date: Wed, 7 Apr 2010 12:39:12 -0700
> From: glassfish_at_javadesktop.org
> To: users_at_glassfish.dev.java.net
> Subject: problem with @SessionScope annotation
>
> Hi guys,
>
> I have a couple of jsf pages (composed using facelets). In the header part of the template I want to display "Login" if the user is not logged in yet and "Logout" if the user is logged in.
>
> What I did so far was to create a backing bean as follows:
>
> [i]@Named
> @SessionScoped
> public class UserManager implements Serializable {
> private @EJB UserService userService;
> private User user;
>
> public User getUser() {
> if (user == null) {
> Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
> if (principal != null) {
> user = userService.getUserByName(principal.getName()); // Find User by j_username.
> }
> }
> return user;
> }
>
> public String getUserName() {
> getUser();
> if(user==null){
> return "Guest";
> }else{
> return getUser().getFirstName()+" "+getUser().getLastName();
> }
> }
>
> public String logout(){
> HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
> if(session!=null){
> session.invalidate();
> }
> return "index";
> }
>
> public boolean isAuthenticated(){
> return getUser()!=null;
> }
> }
> [/i]
>
> The important part in the header looks as follows:
>
> [i]<h:outputText value="Welcome #{userManager.getUserName()}!"
> rendered="#{userManager.isAuthenticated()}"/>
>
> <h:outputLink value="login.xhtml"
> rendered="#{!userManager.isAuthenticated()}">
> Login
> </h:outputLink>
>
> <h:outputLink value="#{userManager.logout()}"
> rendered="#{userManager.isAuthenticated()}">
> Logout
> </h:outputLink>
> [/i]
>
> The problem is that, even if I successfully login in the first page, when I get to the second page it looks like I'm not logged in. And indeed, while debugging, I noticed that the "user" field does not keep its value.
>
> Can anybody suggest what am I doing wrong ?
>
> Thank you,
> Ionut
> [Message sent by forum member 'sionut']
>
> http://forums.java.net/jive/thread.jspa?messageID=395754
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
                                               
_________________________________________________________________
Hotmail has tools for the New Busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_1