jsf - Logout message doesn't show -
When I log out of my application it does not show my logout message
I have an output text to show the message in my output ( & lt; h: outputText id = "message" value = "# {loginMB.message}" /> ):
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt ;! DOCTYPE Structure PUBLIC "- // W3C // DTD XHTML 1.0 Transcription // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> & Lt; Ui: Composition xmlns = "http://www.w3.org/1999/xhtml" xmlns: f = "http://java.sun.com/jsf/core" xmlns: H = "http: // Java. Sun.com/jsf/html "xmlns: o =" http: // java.sun .com / JSF / Facet "Template =" / Web-ANF / Template / Template.XMAMT "& gt; & Lt; Ui: Define name = "content" & gt; & Lt; o: include in form id = "login" view = "true" & gt; & Lt; H: output text id = "message" value = "# {loginMB.message}" /> ... other components ... & lt; / o: form & gt; & Lt; / Ui: defined & gt; & Lt; / ui: Composition & gt; And this is my backing bean:
@ManagedBean @ session executes the public-skilled user BB Serializable {Private string message; Public Zero Logout () {try {message = "You have successfully loggedout"; SecurityUtils.getSubject () logout () .; Faces.invalidateSession (); Faces.redirect ("login.xhtml"); } Hold (exception exception) {... another code ...}} public string getMessage () {return message; } Public Zero Set Message (String Message) {this.message = message; }} Why does not this show my logout message?
Edit:
Logout method:
Public Zero Logout () { SecurityUtils.getSubject (). Logout (); Messages.addFlashGlobalInfo ("You have logged out successfully"); Faces.invalidateSession (); Faces.redirect ("? Login.xhtml to face-redirects = true & amp; lo = t"); } Logout button:
& lt; p: commandButton action = "# {userBB.logout}" value = "logout" />
Why does not this show my logout message?
Because you have handed it as the property of a session and then canceled the session and sending a redirect. The invalidation of the session will destroy the area of the session and all the items stored therein will be destroyed, including session dressed beans. After that the redirect will create a new request and session, and all the sessions in the session will be re-managed to the managed beans, all the properties will be set to the default.
There are 2 problems with this approach:
- To display the message (s),
& lt; h: Output Text & gt; Instead of & lt; h: Message (message) & gt;
Store the message in the session area instead. To resolve your problem, & lt; h: Message (message) & gt; Use the message (s) and FacesContext # addMessage () or, as you already have to add a message in OmniFaces, its utility class, face reference You are using & lt; h: message globalOnly = "true" & gt; to display only the global message (like null containing the customer ID] Thus, everyone should:
& lt; h: message id = "message" globalonline = "right" /> / Code> @ManagedBean @RejectScoped // Special work does not need to leave the session. Public class UserManager {Public Zero Logout (exception) {SecurityUtils} GetSubject (). Logout (); Messages.addFlashGlobalInfo ("You have logged out successfully"); Faces.invalidateSession (); Faces.redirect ("login.xhtml");}}
For interest, here's how it will use "plain JSF":
Public Zero Logout () throws exceptions {SecurityUtils.getSubject () .log out () ; FacesContext reference = FacesContext.getCurrentInstance (); context.addMessage (empty, new FacesMessage ("You have successfully logged out")); ExternalContext External Contact = Reference .getExternalContext (); externalContext.getFlash () setKeepMessages (right). ExternalContext.invalidateSession (); externalContext.redirect ("login.xhtml"); } Important note is that you need a minimum 2.1.27 to get rid of all those problems.
Comments
Post a Comment