JSF Ders23 - Sayfa Navigasyonu (Page Navigation)
Sayfa navigasyonu (Page Navigation) açık (explicit) veya örtülü (implicit) şekilde yapılabilir.
Bu konuda bahsedilecek mevzular
- Açık (explicit) navigation
- Örtülü (implicit) navigation
- Koşullu navigation
- Statik (Static) navigation
- Dinamik (Dynamic) navigation
Örtülü (implicit) navigationu zaten tüm projelerde yaptığımız için onu uzun uzun açıklama gereği duymuyorum. Kısaca Managed Bean sınıfları üzerinde yapılan navigasyon olarak aklınızda tutabilirsiniz. Form üzerinde basılan buton (commandButton,commanLink) bir metot çağırıyor ve bu metodun geriye dönüş değeri gideceğiniz sayfanın ismi olmuş oluyor.Bu kadar.
Açık (explicit) navigation faces-config.xml dosyasında belirtilir.
<from-view-id>/index.xhtml</from-view-id> <navigation-case> <from-outcome>deger1</from-outcome> <to-view-id>/sonuc1.xhtml</to-view-id> </navigation-case> <navigation-case> <from-outcome>deger2</from-outcome> <to-view-id>/sonuc2.xhtml</to-view-id> </navigation-case> <navigation-case> <from-outcome>deger3</from-outcome> <to-view-id>/sonuc3.xhtml</to-view-id> </navigation-case> </navigation-rule> |
Gelişi güzel bir explicit navigasyon kuralı yukarıda verilmiştir. Yukarıdaki sayfa yazılan kod şu anlama gelmektedir.
index.xhtml sayfasında bir butona (commandButton,commandLink vs.) bastınız ve geriye deger1 döndürdü. O zaman yönlendirileceğiniz sayfa sonuc1.xhtml sayfasıdır. Geriye deger2’yi döndürürse yönlendirileceğiniz sayfa sonuc2.xhtml sayfasıdır.Geriye deger3 döndürürse de yönlendirileceğiniz sayfa sonuc3.xhtml sayfasıdır.
Farklı bir durum
<from-view-id>/index.xhtml</from-view-id> <navigation-case> <from-outcome>deger1</from-outcome> <to-view-id>/sonuc1.xhtml</to-view-id> </navigation-case> <navigation-case> <from-outcome>deger2</from-outcome> <to-view-id>/diger.xhtml</to-view-id> </navigation-case> <navigation-case> <from-outcome>deger3</from-outcome> <to-view-id>/diger.xhtml</to-view-id> </navigation-case> </navigation-rule> |
Yani deger1 haricindeki dönüş değerlerinde diger.xhtml sayfasına yönlendiriliyorsunuz.
Bunu şu şekilde ifade edebiliriz.
<navigation-rule> <from-view-id>/index.xhtml</from-view-id> <navigation-case> <from-outcome>deger1</from-outcome> <to-view-id>/sonuc1.xhtml</to-view-id> </navigation-case> <navigation-case> <!-- diger tüm durumlar için boş bırakıldı. --> <to-view-id>/diger.xhtml</to-view-id> </navigation-case> </navigation-rule> |
<navigation-rule> <from-view-id>/index.xhtml</from-view-id> <navigation-case> <from-outcome>deger1</from-outcome> <to-view-id>/sonuc1.xhtml</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/index2.xhtml</from-view-id> <navigation-case> <from-outcome>deger1</from-outcome> <to-view-id>/sonuc1.xhtml</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/index.3.xhtml</from-view-id> <navigation-case> <from-outcome>deger1</from-outcome> <to-view-id>/sonuc1.xhtml</to-view-id> </navigation-case> </navigation-rule> |
Bu durum şu şekilde ifade edilebilir.
<navigation-rule> <from-view-id>*</from-view-id> <navigation-case> <from-outcome>deger1</from-outcome> <to-view-id>/sonuc1.xhtml</to-view-id> <navigation-case> </navigation-rule> |
Not: Eğer iki navigasyon kuralı birbiriyle eşleşirse (*) içermeyen kural önceliği alır.
Koşullu Navigation
Navigation işlemi bir koşula bağlıdır. Kısa bir örnek aşağıda verilmiştir.
Navigation işlemi bir koşula bağlıdır. Kısa bir örnek aşağıda verilmiştir.
<navigation-rule> <from-view-id>*</from-view-id> <navigation-case> <from-outcome>deger1</from-outcome> <if>#{sinifIsmi.degiskenIsmi}</if> <to-view-id>/sonuc1.xhtml</to-view-id> </navigation-rule> |
Koşul if etiketinin içine yazılır.Geriye döndürdüğü değere bağlı olarak yönlendirme işlemi yapılır ya da yapılmaz.
Statik (Static) Navigation
<h:commandButton value="sayfa1'e git" action="#{sinifIsmi.metotIsmi}"/> |
commandButtonun action kısmında, ManagedBean sınıfı içindeki bir metodun ismini yukaridaki şekilde verip metodun döndürdüğü değerle o sayfaya yönlendirmek yerine aşağıdaki şekilde direkt olarak sayfanın ismi verilebilir. Bu static navigationa örnektir.
<h:commandButton value="sayfa1'e git" action="sayfa1"/> |
Dinamik (Dynamic) Navigation
Action controller metodunun geriye döndürdüğü değerle gidilecek sayfayı dolaylı olarak hesaplamak yerine, doğrudan faces-config.xml dosyasında gidilecek sayfa hesaplanabilir.
<navigation-rule> <from-view-id>/index.xhtml</from-view-id> <navigation-case> <to-view-id>#{test.siradakiSayfa}</to-view-id> </navigation-case> </navigation-rule> |
Yorumlar
Yorum Gönder