JSF 2 SelectOneMenu Kullanımı
1. Managed Bean İlk önce bean sınıfımızı oluşturalım ve bean sınıfı çağırılduğı anda liste doldursun. SelectOneMenuBean.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
package com.turkishh.bean; import java.util.ArrayList; import java.util.List; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.model.SelectItem; /** * * @author www.turkishh.com */ @ManagedBean @SessionScoped public class SelectOneMenuBean { public SelectOneMenuBean() { this.konu.add(new SelectItem(1, "JSF Örneği")); this.konu.add(new SelectItem(2, "JSF 2 Örneği")); this.konu.add(new SelectItem(3, "JPA Örneği")); this.konu.add(new SelectItem(4, "Maven Örneği")); } private List<SelectItem> konu = new ArrayList<SelectItem>(); private String selectedKonu = ""; private String selectedSeviye = ""; public List<SelectItem> getKonu() { return konu; } public void setKonu(List<SelectItem> konu) { this.konu = konu; } public String getSelectedKonu() { return selectedKonu; } public void setSelectedKonu(String selectedKonu) { this.selectedKonu = selectedKonu; } public String getSelectedSeviye() { return selectedSeviye; } public void setSelectedSeviye(String selectedSeviye) { this.selectedSeviye = selectedSeviye; } public String konuSec() { return "deger.xhtml"; } } |
Arayüz oluşturuyoruz ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?xml version='1.0' encoding='UTF-8' ?> <!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://xmlns.jcp.org/jsf/core"> <h:head> <title>www.turkishh.com</title> </h:head> <h:body> <h:form> <h1> <h:outputText value="www.turkishh.com JSF 2.2 Örneği" /> </h1> <h2> <h:outputText value="SelectOneMenu Örneği" /> </h2> <br /> <h:panelGrid columns="2"> <h:outputText value="Konu Seçiniz :" /> <h:selectOneMenu value="#{selectOneMenuBean.selectedKonu}"> <f:selectItems value="#{selectOneMenuBean.konu}" /> </h:selectOneMenu> <h:outputText value="Seviyeyi Seçiniz :" /> <h:selectOneMenu value="#{selectOneMenuBean.selectedSeviye}"> <f:selectItem itemValue="1" itemLabel="1 .Seviye" /> <f:selectItem itemValue="2" itemLabel="2. Seviye" /> <f:selectItem itemValue="3" itemLabel="3 .Seviye" /> </h:selectOneMenu> </h:panelGrid> <br /><br /><br /> <h:commandButton value="Konu Seç" action="#{selectOneMenuBean.konuSec()}"> </h:commandButton> </h:form> </h:body> </html> |
1 2 3 4 5 |
Ekran çıktısı : <img class="alignnone" alt="" src="http://www.turkishh.com/wp-content/uploads/2014/07/deneme.png" width="536" height="342" /> ikinci sayfamız . |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version='1.0' encoding='UTF-8' ?> <!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"> <h:head> <title>Facelet Title</title> </h:head> <h:body> <h:panelGrid columns="1"> <h:outputText value="Seçilen konu : #{selectOneMenuBean.selectedKonu}"/> <h:outputText value="Seçilen seviye : #{selectOneMenuBean.selectedSeviye}"/> </h:panelGrid> </h:body> </html> |
Çıktısı : Umarım yararlı olmuştur 😉...