JSF Ders32 - View Params
Çoğu kaynak bununla ilgili kafa karıştırıcı cümleler ve örnekler içerir. Konunun özeti şudur.
- f:viewParams ile gelen request (istek) parametreleri yakalanır
- h:link, h:button ile istek parametresi gönderilir.
<f:viewParam name="..." value="..."/> <f:viewParam name="..." value="..."/> </f:metadata> |
ViewParamları metadata içine yerleştirerek kullanır. ViewParamları kullanabilmek için ayrıca isim uzaylarına
- xmlns:f="http://java.sun.com/jsf/core"
h:link ve h:button yardımıyla parametre gönderilmesi de aşağıdaki şekildedir.
<h:button outcome="sayfa?par1=a&par2=b" value="..."/> |
Şimdi örnek programı paylaşalım.
diger.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:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>diger.xhtml</title> </h:head> <h:body> <f:metadata> <f:viewParam name="ad" /> </f:metadata> <h:outputText value="Direkt urlden giriş : #{ad}" /> <br /> </h:body> </html>
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:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> <h:head> <title>index.xhtml</title> </h:head> <h:body> <h:form> Ad<br /> <h:inputText value="#{test.ad}" /><br /><br /> <h:commandButton value="gonder" action="diger2?faces-redirect=true" /> </h:form> </h:body> </html>
diger2.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:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>diger2.xhtml</title> </h:head> <h:body> <f:metadata> <f:viewParam name="ad2" value="#{test.ad}" /> </f:metadata> <h:outputText value="formdan giriş : #{test.ad}" /> <br /> </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:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> <h:head> <title>index2.xhtml</title> </h:head> <h:body> <h:link outcome="diger3?faces-redirect=true;&ad=enes" value="diger3 sayfasına parametreyle git."/><br/><br/> <h:button outcome="diger4?faces-redirect=true;&ad=enes" value="diger4 sayfasına parametreyle git."/> </h:body> </html>
diger3.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:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>diger3.xhtml</title> </h:head> <h:body> <f:metadata> <f:viewParam name="ad"/> </f:metadata> <h1>h:link</h1> <h2>ad : #{ad}</h2> </h:body> </html>
diger4.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:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>diger4.xhtml</title> </h:head> <h:body> <f:metadata> <f:viewParam name="ad"/> </f:metadata> <h1>h:button</h1> <h2>ad : #{ad}</h2> </h:body> </html>
Yorumlar
Yorum Gönder