• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

<h:commandLink> rendered not updating on logout

 
Greenhorn
Posts: 8
MySQL Database Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm still new to JSF so I'm looking for any advice I can get. I have a problem updating my JSF components rendered attribute. Here is my code:

index.xhtml


MenuBean.java

faces-config.xml

I can login and logout just fine but the problem is that when I logout and get sent back to my index page, I can still see my logout button that shouldn't be rendered anymore. This goes away after clicking through another link so I thought that using redirect should work but to no avail.

Any tips will be much appreciated.
Thanks!
Calvin
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, for one thing, "rendered="#{menuBean.loginStatus()}"" is incorrect.

It should be "rendered="#{menuBean.loginStatus}"", where the menuBean should present a public method named "isLoginStatus()" that returns true when logged in and false when not logged in.

 
Calvin Hughes
Greenhorn
Posts: 8
MySQL Database Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Tim. I fixed the problem you mentioned but it doesn't seem to affect the problem I'm seeing. It is more like my page just isn't redirecting when it should be and I don't know why.

I would make it a regular <h:link> like all the rest of my buttons but for some reason JSF calls the outcome method of my link when the page is created so it automatically logs me out just from viewing the admin page.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The difference between h:link and h:commandLink is that h:link does an immediate jump to the target, disregarding any updates made to the form. commandLink, on the other hand, validates the inputs, and if the data is valid, updates the backing bean, then invokes the action method. Which, by the way, should be declared as "action="#{menuBean.logout}"". Another case where you need to lose the parentheses.

The action method must be a public method with no parameters, and returning a String. The String is the navigation token, which originally was the label of a navigation rule, but in JSF2 can also be a direct reference to another JSF View. When it's empty or null, the invoking page is simply redisplayed.

The link tag was added for JSF2 as part of the support for bookmarkable JSF URLs. It should be used sparingly. The commandLink and commandButtons are more appropriate when doing data updates.

You can add the "redirect" element to a navigation rule and it will cause the displayed URL to match the destination. This costs extra, but is very useful/important in cases where the usual "URL lag" is not desirable, such as when navigating to a secured View.
 
Calvin Hughes
Greenhorn
Posts: 8
MySQL Database Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Tim.

Thank you Thank you. Your comment lead me in the right direction to figuring out my problem.

It came down to <from-action> with <h:commandLink action=""> is not the same thing as using a <from-outcome> tag with <h:link outcome=""> in the faces-config.xml file.

I changed my method to not return a string that can be interpreted as a reference to a view and had to change my navigation rule back to using <from-outcome> in faces-config.xml

public String logout(){
FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext ectx = ctx.getExternalContext();
ectx.invalidateSession();
return "home";
}

<navigation-rule>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>

Thanks again!
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic