Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how can i execute a method before a jsf page loads. help with <f:event ..>

obinnahenreeApr 5 2011 — edited Apr 13 2011
hi, i want to execute a managed bean method while/before a page renders. i am checking if a particular value is in the session or not. The application is a Javaee6 app
, and am using netbeans 6.9.
This is what i have done so far with <f:event />.:

the page is a facelets template client:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui"
template="./../templates/adminhometemplate.xhtml">


<f:event type="preRenderView"
listener="#{loginMBean.checkSessionValue}" />

........
-------------------------------------------------------------------------------------------------here is the method in the managed bean
public void checkSessionValue(ComponentSystemEvent cse) {
FacesContext context = FacesContext.getCurrentInstance();
String strtoken = (String) context.getExternalContext().getSessionMap().get("currentToken");
if (strtoken == null) {
NavigationHandler nav = context.getApplication().getNavigationHandler();
nav.handleNavigation(context, null, "/ui/somepage?faces-redirect=true");
context.renderResponse();
}
}

------------------------

this does not seem to be working. i have tried to set my session expiry to 1 in web.xml to test, but it does not work.

I have also tried to use a <c:if /> with a <c:redirect../> but <c:redirect ..> is just not showing up in netbeans. i dont know why.

how can i achieve this?
thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 11 2011
Added on Apr 5 2011
3 comments
2,636 views