14. Sürüm 9: Primefaces ile web katmanının uygulanması
Önkoşul: [ref3]'teki "Primefaces'e Giriş" bölümünü okuyun.
Soru 1: [Web Application] türünde yeni bir Maven projesi oluşturun; bu projede, önceki örnekteki XHTML sayfaları Primefaces bileşenleriyle oluşturulacaktır. Bean'lerde herhangi bir değişiklik yapılmayacaktır.
Ana sayfa <p:panel>, <p:inputText>, <p:selectOneMenu> ve <p:message> bileşenlerini kullanır:
![]() |
Hatalı bir giriş:
![]() |
Bir simülasyon:
![]() |
Simülasyon listesi <p:dataTable>, <p:commandLink> bileşenlerini kullanır:
![]() |
AJAX yöntemleri, sayfanın tamamını içeren id='form' alanını güncelleyecektir (aşağıdaki 11. satıra bakınız):
<?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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view locale="#{sessionData.locale}">
...
<h:body style="background-image: url('${request.contextPath}/resources/images/standard.jpg');">
<h:form id="formulaire">
<!-- başlık -->
<ui:include src="entete.xhtml" />
<!-- içerik -->
<ui:insert name="part1" >
Gestion des assistantes maternelles
</ui:insert>
<ui:insert name="part2"/>
</h:form>
</h:body>
</f:view>
</html>
Uygulamanız çalışır hale geldiğinde, [entete.xhtml] sayfasını aşağıdaki sayfayla değiştirin:
<?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://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<!-- başlık -->
<h:panelGroup>
<h2><h:outputText value="#{msg['form.titre']}"/></h2>
</h:panelGroup>
<p:menubar id="menu" header="Menu" style="width: 500px">
<p:submenu label="#{msg['form.menu.simulation']}">
<p:menuitem id="cmdFaireSimulation" style="width: 200px" value="#{msg['form.menu.faireSimulation']}" actionListener="#{form.faireSimulation}" rendered="#{sessionData.menu.faireSimulation}" update=":formulaire:contenu"/>
<p:menuitem id="cmdEffacerSimulation" style="width: 200px" onclick="raz();" immediate="true" value="#{msg['form.menu.effacerSimulation']}" actionListener="#{form.effacerSimulation}" rendered="#{sessionData.menu.effacerSimulation}" update=":formulaire:contenu"/>
<p:menuitem id="cmdEnregistrerSimulation" style="width: 200px" immediate="true" value="#{msg['form.menu.enregistrerSimulation']}" actionListener="#{form.enregistrerSimulation}" rendered="#{sessionData.menu.enregistrerSimulation}" update=":formulaire:contenu"/>
</p:submenu>
<p:submenu label="Navigation">
<p:menuitem id="cmdRetourSimulateur" style="width: 200px" immediate="true" value="#{msg['form.menu.retourSimulateur']}" actionListener="#{form.retourSimulateur}" rendered="#{sessionData.menu.retourSimulateur}" update=":formulaire:contenu"/>
<p:menuitem id="cmdVoirSimulations" style="width: 200px" immediate="true" value="#{msg['form.menu.voirSimulations']}" actionListener="#{form.voirSimulations}" rendered="#{sessionData.menu.voirSimulations}" update=":formulaire:contenu"/>
</p:submenu>
<p:menuitem id="cmdTerminerSession" immediate="true" value="#{msg['form.menu.terminerSession']}" actionListener="#{form.terminerSession}" rendered="#{sessionData.menu.terminerSession}" update=":formulaire:contenu"/>
</p:menubar>
<p:spacer height="50px"/>
</html>
- 15. satır: bir Primefaces menü çubuğu,
- 16. satır: bu çubuktaki bir menü seçeneği,
- 17. satır: bu menü seçeneğindeki bir öğe.
Bu değişiklik şablonu etkilemez. Yeni görünüm şöyledir:




