how can i execute a method before a jsf page loads. help with <f:event ..>
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