2009-09-17 14 views
6

Web portalı oluşturmak için RichFacecs ile JSF kullanıyorum. Kullanıcıyı oturum zaman aşımı oturum açma sayfasına yönlendirmek istiyorum.JSF-Richfaces-facelet içinde oturum zaman aşımına yönlendiriliyor

<error-page> 
    <exception-type>java.lang.SecurityException</exception-type> 
    <location>/Login.jsf</location> 
</error-page> 

aşağıdaki Ama bu benim için çalışmıyor gibi oturumun bitiminden içinde SecurityException atmaya çalışıyordu/sahne çıkış yaptı. Bunu işlemenin doğru yolu hangisi?

cevap

7

Bu yapmalıyım:

<error-page> 
    <exception-type>javax.faces.application.ViewExpiredException</exception-type> 
    <location>/sessionExpired.jsf</location> 
</error-page> 
+0

Teşekkür Cevap. Bunu denedim ve ajax isteği için çalışmıyor – Jinesh

+0

Oturumun süresi dolmuş sayfayı nasıl uyguladığınızı gösterir misiniz? Kullanmanız gereken yönlendirme işlevi de zaman aşımına uğramamıştır =) –

+0

Oturum açma süresindeki oturum açma sayfasını yeniden yönlendiriyorum. Başka bir çalışma çözümüm var. Şimdi ben backing fasulye bu FacesContext.getCurrentInstance(). GetExternalContext(). Yönlendirme ("login.jsf") gibi yönlendiriyorum. Bu uygun bir yol mu? – Jinesh

0

Başka bir çözüm Sonra

@Override 
public UIViewRoot restoreView(FacesContext facesContext, String viewId) { 
/** 
* {@link javax.faces.application.ViewExpiredException}. This happens only when we try to logout from timed out pages. 
*/ 
    UIViewRoot root = null; 
    root = parent.restoreView(facesContext, viewId); 
    if(root == null) {   
     root = createView(facesContext, viewId); 
    } 
    return root; 
} 

Eğer eklemek gerekir restoreView yöntemini yüzleri-config.xml ViewHandler uzanır CustomViewHandler oluşturmak ve geçersiz kılmak olduğunu

<view-handler>com.demo.CustomViewHandler</view-handler> 

Bu, ViewExpiredException için

+0

Not: "Ebeveyn" in "süper" olması gerektiğini düşünüyorum ve ayrıca createView öğesine eklenebilir. Ayrıca ViewHandler uygulamasının com.sun.faces.application.ViewHandlerImpl gibi bir uygulamasının genişletilmesini ve böylece ViewHandler sınıflarının tümünü yeniden yazmanız gerekmediğini öneririm. – Adam

1

Çözüm, Richfaces ürününü kendi session expired event kullanmaktır.

sona eğilimli sayfanıza ekleyin:

<a4j:region> 
<script language="javascript"> 
A4J.AJAX.onExpired = function(loc, expiredMsg){ 
alert('expired!'); 
window.location = "/login.jsf"; 
} 
</script> 
</a4j:region> 

fazla bilgi RichFaces belgelerine bulunabilir: Ben oturumu sona ermesinden sonra A4J isteklerini yaparken http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/ArchitectureOverview.html#SessionExpiredHandling

1

bazı sorunlar vardı. benim için o sorunu çözer, benim web.xml''deki bu

<context-param> 
    <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name> 
    <param-value>true</param-value> 
</context-param> 

koydu.

Eğer Web.xml bir zaman aşımı koymak ve bu parçacığı gösterildiği gibi bir zaman aşımı filtresi kaydetme gerektiğini
4

: böyle yapılması gereken ajax durumunda Auto-logout in JSF Application , senin yönlendirme etti: için

String facesRequestHeader = httpServletRequest 
      .getHeader("Faces-Request"); 

    boolean isAjaxRequest = facesRequestHeader != null 
      && facesRequestHeader.equals("partial/ajax"); 

    if(isAjaxRequest) 
    { 
      String url = MessageFormat.format("{0}://{1}:{2,number,####0}{3}", 
      request.getScheme(), request.getServerName(), 
      request.getServerPort(), timeoutPath); 

      PrintWriter pw = response.getWriter(); 
       pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 
      pw.println("<partial-response><redirect url=\"" + url 
      + "\"></redirect></partial-response>"); 
      pw.flush();); 
    } 
    else 
    { 
     httpServletResponse.sendRedirect(timeoutPath); 
    } 
İlgili konular