JSF Ders31 - Composite Components (Bileşik Ögeler)


   Composite Components (Bileşik Ögeler) tekrar kullanılabilir ve parametre geçirilebilir
facelet kodlarının ham halidir.

Aşamalar
  • resource klasörü ve onun altına util(farklı bir isim de olabilir.) klasörü açılır.Bu klasörün içinebir .xhtml uzantılı dosya oluşturulur.
  • Composite component sayfası için xmlns:cc="http://xmlns.jcp.org/jsf/composite" ifadesi isim uzaylarına eklenir.
  • Composite componenti kullanacak sayfa için xmlns:utils="http://xmlns.jcp.org/jsf/composite/utils" ifadesi isim uzaylarına eklenir.
Örnek bir composite components dosyası aşağıda verilmiştir.

test.xhtml

<cc:implementation>
test1
</cc:implementation>


Bu dosya


   <utils:test/>


şeklinde çağrılarak kullanılır.

Composite Componentlerde Attribute Kullanımı

Composite componentlerde attributeler interface tagının içine eklenir. Bununla ilgili bir örnek aşağıda verilmiştir.

Attribute parametreleri
  • name: Attribute ismini belirtir.
  • required: Attributeün girilmesini zorunlu kılar.
  • default: Attribute defaul değer vermek için kullanılır.
test.xhtml

<cc:interface>
   <cc:attribute name="at1"/>
   <cc:attribute name="at2" required="true"/>
   <cc:attribute name="at3" default="enes"/>
</cc:interface> 

<cc:implementation>
  <p> 1.attribute degeri : #{cc.attrs.at1}</p>
  <p> 2.attribute degeri : #{cc.attrs.at2}</p>
  <p> 3.attribute degeri : #{cc.attrs.at3}</p>
</cc:implementation>


Çağrılışı

<cc:utils at1="deneme" at2="deneme2"/>


 Çıktısı

 1.attribute degeri : deneme 
 2.attribute degeri : deneme2
 3.attribute degeri : deneme3


Örnek bir program aşağıda verilmiştir.

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:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
 xmlns:utils="http://xmlns.jcp.org/jsf/composite/utils">
<h:head>
 <title>index.xhtml</title> 
</h:head>

<h:body>

 <utils:kompozit ad="enes" soyad="cetin" color="blue"/>

</h:body>


</html>

kompozit.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"
 xmlns:cc="http://xmlns.jcp.org/jsf/composite">


 <h:outputStylesheet library="css" name="stil.css" />

 <cc:interface>
  <cc:attribute name="ad" required="true" />
  <cc:attribute name="soyad" default="belirtilmedi" />
  <cc:attribute name="color" default="black" />
 </cc:interface>

 <cc:implementation>
  <h1 class="#{cc.attrs.color}">#{cc.attrs.ad} #{cc.attrs.soyad}</h1>
 </cc:implementation>

</html>

stil.css
@CHARSET "UTF-8";


.black{
 color:black;
}

.red{
 color:red;
}

.blue{
 color:blue;
}

JSF Composite Components

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)