JSF Ders34 - Faces Flow


   Flowlar sayfa gruplarıdır. Bu gruplara sadece 1 sayfa üzerinden giriş yapılabilir.Giriş yapıldıktan sonra istenildiği gibi bu grup içindeki sayfalarda dolaşılabilir. Flowlardan çıkış ise 1 veya daha fazla sayfdan yapılabilir. Genelde çıkış için tek bir sayfa vardır.

Flowlar flowscoped beani kullanır. Bu scope kullanıcı sayfalar üzerinde istenildiği gibi gezibildiği için view scopetan daha geniştir. Kullanıcı sadece bu sayfalar üzerinde bilgileri saklandığı için ise session scopetan daha dardır.

Yapım aşamaları
  • Bir flow klasör ismi oluşturulur. (Mesela flowum klasörü).
  • Klasör ismi ile aynı olacak şekilde bir .xml dosyası oluşturulur. (flowum-flow.xml)
  • Klasör ismi ile flowa giriş ismi aynı olacak şekilde başlangıç sayfası oluşturulur. (flowum.xhtml)
  • Diğer sayfalar keyfi oluşturulur.(sayfa1.xhtml,sayfa2.xhtml,.....)
  • Klasör ismi ile aynı olacak şekilde en az bir tane çıkış sayfası oluşturulur.                           (flowum-return.xhtml) Çıkış sayfası üzerindeyken flowdan çıkılabilir veya flowdaki diğer sayfalara dönüş yapılabilir. Ayrıca çıkış sayfası flowun klasörü içinde değil, direkt olarak WebContentin içinde olmalıdır.
Kurallar
  • Bean sınıfı scopeu olarak @FlowScoped kullanılır.
  • @ManagedBean anotasyonu yerine @Named anotasyonu kullanılır.

@Named
@FlowScoped("flowIsmi")
public class A{...}

  • Bir değişken değeri direkt olarak beande saklanabileceği gibi direkt olarak flowda da saklanabilir.

#{a.degisken}
      


#{flowScope.degisken}
      

Flowları .xml Dosyasıyla Yapılandırma
  • Başlangıç sayfası tanımlama

<start-node>startPage</start-node>
<view id="startPage">
     <vdl-document>/flowIsmi/baslangic.xhtml</vdl-document>
</view>      
  • Return sayfası tanmlama

<flow-return id="..">
                <from-outcome>......</from-outcome>
</flow-return>      
  • Diğer sayfaları tanımlama

<view id="...">
                 <vdl-document>....</vdl-document>
</view>
      
  • Koşullu sayfaları tanımlama

<switch id="...">
    <case><if>#{...}</if>
          <from-outcome>...</from-outcome>
    </case>
    <case><if>#{...}</if>
          <from-outcome>...</from-outcome>
     </case>
    <default-outcome>…</default-outcome>
</switch>
      
  • Bunlar flowKlasor/flowKlasor-flow.xml dosyasında yapılmaktadır. Bu dosya içeriği aşağıda verilmiştir.

<?xml version='1.0' encoding='UTF-8'?>
         <faces-config … version="2.2">
         <flow-definition id="flowIsmi">
                 …
         </flow-definition>
</faces-config>
      


<flow-return id="..">…</flow-return>   



index.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html">

<h:head>
 <title>index.xhtml</title>
</h:head>


<h:body>


 <h:form>
  <h:commandButton value="Flowa Giriş" action="flowum/flowum?faces-redirect=true"/>
 </h:form>


</h:body>

</html>

index2.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html">

<h:head>
 <title>index2.xhtml</title>
</h:head>


<h:body>

<h1>index2.xhtml</h1>
 

</h:body>

</html>

flowum.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html">

<h:head>
 <title>flowum.xhtml</title>
 <h:outputStylesheet library="css" name="stil.css"/>
</h:head>


<h:body>

 <h1>Flowun Giriş Sayfası</h1>
 <h5 style="color:red;">*Sadece flow içi sayfalara erişim</h5>
 <hr/>
 <h2 style="color:blue;">Flow içi</h2>
 <h:form>
 <h:commandButton value="giris sayfası" action="flowum?faces-redirect=true"/><br/>
 <h:commandButton value="sayfa1" action="sayfa1?faces-redirect=true"/><br/>
 <h:commandButton value="sayfa2" action="sayfa2?faces-redirect=true"/><br/>
 <h:commandButton value="sayfa3" action="sayfa3?faces-redirect=true"/><br/>
 <h:commandButton value="cikis sayfası" action="/flowum-return"/><br/>
 <br/><br/>
    <hr/>
    <h2 style="color:blue;">Flow dışı</h2>
    <h:commandButton value="index" action="index?faces-redirect=true"/><br/>
    <h:commandButton value="index2" action="index2?faces-redirect=true"/><br/>
 </h:form>



</h:body>

</html>

sayfa1.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html">

<h:head>
 <title>sayfa1.xhtml</title>
</h:head>


<h:body>

 <h1>Sayfa1</h1>
 <h5 style="color:red;">*Sadece flow içi sayfalara erişim</h5>
 <hr/>
 <h2 style="color:blue;">Flow içi</h2>
    <h:form>
       <h:commandButton value="giris sayfası" action="flowum?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa1" action="sayfa1?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa2" action="sayfa2?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa3" action="sayfa3?faces-redirect=true"/><br/>
    <h:commandButton value="cikis sayfası" action="/flowum-return?faces-redirect=true"/><br/>
    <br/><br/>
 <hr/>
    <h2 style="color:blue;">Flow dışı</h2>
    
    <h:commandButton value="index" action="index?faces-redirect=true"/><br/>
    <h:commandButton value="index2" action="index2?faces-redirect=true"/><br/>
 </h:form>
</h:body>

</html>

sayfa2.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html">

<h:head>
 <title>sayfa2.xhtml</title>
</h:head>


<h:body>
    <h1>Sayfa2</h1>
    <h5 style="color:red;">*Sadece flow içi sayfalara erişim</h5>
    <hr/>
 <h2 style="color:blue;">Flow içi</h2>
    <h:form>
       <h:commandButton value="giris sayfası" action="flowum?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa1" action="sayfa1?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa2" action="sayfa2?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa3" action="sayfa3?faces-redirect=true"/><br/>
    <h:commandButton value="cikis sayfası" action="/flowum-return?faces-redirect=true"/><br/>
    <br/><br/>
 <hr/>
    <h2 style="color:blue;">Flow dışı</h2>
    <h:commandButton value="index" action="index?faces-redirect=true"/><br/>
    <h:commandButton value="index2" action="index2?faces-redirect=true"/><br/>
 </h:form>
 

</h:body>

</html>

sayfa3.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html">

<h:head>
 <title>sayfa3.xhtml</title>
</h:head>


<h:body>

 <h1>Sayfa3</h1>
 <h5 style="color:red;">*Sadece flow içi sayfalara erişim</h5>
 <hr/>
 <h2 style="color:blue;">Flow içi</h2>
    <h:form>
       <h:commandButton value="giris sayfası" action="flowum?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa1" action="sayfa1?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa2" action="sayfa2?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa3" action="sayfa3?faces-redirect=true"/><br/>
    <h:commandButton value="cikis sayfası" action="/flowum-return?faces-redirect=true"/><br/>
    <br/><br/>
 <hr/>
    <h2 style="color:blue;">Flow dışı</h2>
    
    <h:commandButton value="index" action="index?faces-redirect=true"/><br/>
    <h:commandButton value="index2" action="index2?faces-redirect=true"/><br/>
    
    
 </h:form>

</h:body>

</html>

flowum-return.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html">

<h:head>
 <title>flowum-return.xhtml</title>
</h:head>


<h:body>

 <h1>Çıkış Sayfası</h1>
 <h5 style="color:red;">*Hem flow içi sayfalara hem de flow dışı sayfalara erişim</h5>
 <hr/>
 <h2 style="color:blue;">Flow içi</h2>
    <h:form>
       <h:commandButton value="giris sayfası" action="flowum/flowum?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa1" action="flowum/flowum?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa2" action="flowum/sayfa2?faces-redirect=true"/><br/>
    <h:commandButton value="sayfa3" action="flowum/sayfa3?faces-redirect=true"/><br/>
    <h:commandButton value="cikis sayfası" action="/flowum-return?faces-redirect=true"/><br/>
    <br/><br/>
    <hr/>
    <h2 style="color:blue;">Flow dışı</h2>
    <h:commandButton value="index" action="index?faces-redirect=true"/><br/>
    <h:commandButton value="index2" action="index2?faces-redirect=true"/><br/>
 </h:form>

</h:body>

</html>


JSF Faces Flow

JSF Faces Flow

JSF Faces Flow

JSF Faces Flow

JSF Faces Flow

JSF Faces Flow

Yorumlar

Bu blogdaki popüler yayınlar

Java SE Ders24 - Composition (Kompozisyon)

Spring Ders20 - Aspect Oriented Programming - AspectJ Annotation Style

JSF Ders30 - Page Template (Sayfa Şablonu)