FYI... Make sure that you are not defining the faces-config.xml deployment 
descriptor as this will cause the configuration to be loaded 2x
 
http://wiki.apache.org/myfaces/FAQ#Twice
 
-----Original Message-----
From: Francisco Passos [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 27, 2007 5:44 AM
To: MyFaces Discussion
Subject: Re: Phase Listener execute only once ???


The way I solved a similar problem was putting into my bean onLoad method the 
logic to decide whether or not it had already run or not (having a private 
boolean and testing it before running whatever you have to run, plus setting it 
on the first run to prevent it from running later). 

Although this is a clunky solution if you intend to do it on many beans, you 
can consider making your beans extend an abstract one and including this 
"rerun-prevention" on the base class.

Francisco Passos 


On 6/26/07, bansi < [EMAIL PROTECTED]> wrote: 


We have Homegrown Authentication System which on successfull authentication
returns "EmployeeID" in the form of Request Header Variables.
I am using  "afterPhase" method of PhaseListener to call "onPageLoad" method 
of LoginBean by checking the viewId as shown below

if (viewId.endsWith("login.xhtml")) {
      String managedBeanName = getManagedBeanNameFromView(viewId);

      Object object = facesContext.getApplication ().createValueBinding("#{"
+ managedBeanName + "}").getValue(facesContext);
      if (object == null)
        logger.error("OnPageLoad cannot be executed, no such managed bean:"+
managedBeanName);
      else {
        Login loginBean = (Login) object;
        loginBean.onPageLoad();
      }
    }
public String getManagedBeanNameFromView(String viewId) {
          String pageName; 
          if (viewId.endsWith("login.xhtml")) {
             pageName = viewId.substring(1, viewId.length() - 6);
          }
          else{
                  pageName = viewId.substring(1, viewId.length () - 10);
          }
            return  pageName+"Bean";

          }
public PhaseId getPhaseId()
  {

          return PhaseId.RESTORE_VIEW;

  }

The onPageLoad method of LoginBean retrieves "employeeID" from request 
header variables and use employeeID to retrieve userID and userRoles from
database as shown below
public void onPageLoad() {

          Map requestHeaderMap =

FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap(); 


         String employeeID = (String) requestHeaderMap.get("EmployeeID");

         userId = getUserId(Long.valueOf(employeeID )); // calls database
        userRoles = getUserRoles(userId);        // calls database 
         userInfo.setUserId(userId);  //userInfo is pojo
         userInfo.setUserRoles(userRoles);

         /* Store Nams User Id in Session */
          HttpSession userSession =
               (HttpSession) 
FacesContext.getCurrentInstance().getExternalContext()
                                         .getSession(true);
           userSession.setAttribute("userInfo", userInfo);

           //   UserInfoHolder is a Thread Local 
            UserInfoHolder.setUserInfo(userInfo);

    }

The problem is whenever i navigate back & forth between the pages , the
query is fired to retrieve userID and userRoles from database which i wanna 
happen only once i.e. how do i make  getUserID() and getUserRoles() method
fire only once
Any pointers/suggestions will be highly appreciated


--
View this message in context: 
http://www.nabble.com/Phase-Listener-execute-only-once-----tf3983959.html#a11311025
Sent from the MyFaces - Users mailing list archive at Nabble.com.




Reply via email to