| At line 1 changed one line |
| !!Sorgenti del corso |
| !!Risorse del Corso JSF 2.0 Base |
| At line 3 removed one line |
|
| At line 5 changed 3 lines |
| %%tab-Parte1 |
| !!Parte 1 |
| !index.html (v1) |
| %%tab-Requisiti |
| !!Requisiti |
| ;IDE:__Netbeans 6.9__ versione Java Web oppure __Eclipse 3.5.2__ con Server Adapter "Glassfish v3 JavaEE6" |
| ;Application Server: Glassfish v3 (Java EE6) |
|
| /% |
| %%tab-Step1 |
| !!Step 1: La navigazione |
|
| !index.html |
| At line 27 changed one line |
| !list.xhtml (v1) |
| !list.xhtml |
| At line 49 changed one line |
| %%tab-Parte2 |
| %%tab-Step2 |
| At line 51 changed one line |
| !!Parte 2 |
| !!Step 2: Facelets templating |
|
| !Logo per l'header |
| At line 61 added one line |
| [salva con nome... |../cartella/sottocartella/header_logo.gif] |
| At line 54 changed one line |
| !masterLayout.xhtml (v1) |
| !masterLayout.xhtml |
| At line 83 changed one line |
| !index.xhtml (v2) |
| !index.xhtml |
| At line 100 changed one line |
| !list.xhtml (v2) |
| !list.xhtml |
| At line 119 changed one line |
| !style.css (v1) |
| !style.css |
| At line 140 changed one line |
| %%tab-Parte3 |
| %%tab-Step3 |
| At line 142 changed one line |
| !!Parte 3 |
| !!Step 3: i Managed Baen e lo scope |
| At line 195 changed one line |
| %%tab-Parte4 |
| %%tab-Step4 |
| At line 197 changed one line |
| !!Parte 4 |
| !!Step 4: inclusione con facelets e i componenti tabella |
| At line 245 changed one line |
| private Date dataFIne; |
| private Date dataFine; |
| At line 260 changed 2 lines |
| public Date getDataFIne() { |
| return dataFIne; |
| public Date getDataFine() { |
| return dataFine; |
| At line 263 changed 2 lines |
| public void setDataFIne(Date dataFIne) { |
| this.dataFIne = dataFIne; |
| public void setDataFine(Date dataFine) { |
| this.dataFine = dataFine; |
| At line 286 added 55 lines |
|
| !ListController.java |
| %%prettify |
| {{{ |
| /* |
| * To change this template, choose Tools | Templates |
| * and open the template in the editor. |
| */ |
| package corsojsf.managedbeans; |
|
| import corsojsf.model.Camera; |
| import corsojsf.model.Prenotazione; |
| import java.util.LinkedList; |
| import java.util.List; |
| import javax.faces.bean.ManagedBean; |
| import javax.faces.bean.SessionScoped; |
|
| @ManagedBean |
| @SessionScoped |
| public class ListController { |
|
| private List<Camera> camere = new LinkedList<Camera>(); |
| private List<Prenotazione> prenotazioni = new LinkedList<Prenotazione>(); |
| private Camera camera = new Camera(); |
| private Prenotazione prenotazione = new Prenotazione(); |
|
| public List<Camera> getCamere() { |
| return camere; |
| } |
|
| public List<Prenotazione> getPrenotazioni() { |
| return prenotazioni; |
| } |
|
| public Camera getCamera() { |
| return camera; |
| } |
|
| public void setCamera(Camera camera) { |
| this.camera = camera; |
| } |
|
| public Prenotazione getPrenotazione() { |
| return prenotazione; |
| } |
|
| public void setPrenotazione(Prenotazione prenotazione) { |
| this.prenotazione = prenotazione; |
| } |
| } |
|
| }}} |
| /% |
|
|
| At line 338 changed one line |
| <ui:composition |
| <ui:composition xmlns="http://www.w3.org/1999/xhtml" |
| At line 378 changed one line |
| %%tab-Parte5 |
| %%tab-Step5 |
| At line 380 changed one line |
| !!Parte 5 |
| !!Step 5: form di inserimento, componenti I/O e metodi action. |
| At line 503 added one line |
|
| At line 505 added 2 lines |
| %%tab-Step6 |
| !!Step 6: metodi action con parametro |
| At line 441 removed 3 lines |
| %%tab-Parte6 |
| !!Parte 6 |
|
| At line 539 added 2 lines |
| %%tab-Step7 |
| !!Step 7: i convertitori e i componenti "select" |
| At line 476 removed 3 lines |
| %%tab-Parte7 |
| !!Parte 7 |
|
| At line 739 added 3 lines |
| /% |
| %%tab-Step8 |
| !!Step 8: validazione standard e metodi di validazione |
| At line 743 added 19 lines |
| !camera.xhtml (porzione) |
| %%prettify |
| {{{ |
| |
| [...] |
| |
| <h:outputLabel for="posti" value="posti letto"/> |
| <h:inputText id="posti" value="#{listController.camera.numeroPosti}" |
| validatorMessage="Il numero di posti deve essere compreso tra 1 e 5"> |
| <f:validateLongRange minimum="1" maximum="5"/> |
| </h:inputText> |
| <h:outputLabel for="prezzo" value="prezzo"/> |
| <h:inputText id="prezzo" value="#{listController.camera.prezzo}" |
| validator="#{listController.validatePrezzo}"/> |
| |
| [...] |
| |
| }}} |
| /% |
| At line 763 added 17 lines |
| !ListController.java (porzione) |
| %%prettify |
| {{{ |
| |
| [...] |
| /*validator*/ |
| public void validatePrezzo(FacesContext context, UIComponent component, Object enteredValue) throws ValidatorException { |
| BigDecimal prezzo=(BigDecimal)enteredValue; |
| if (prezzo.intValue()%2!=0){ |
| throw new ValidatorException( |
| new FacesMessage("Errore di validazione: la parte intera del prezzo deve essere pari")); |
| } |
| } |
| |
| [...] |
| |
| }}} |
| At line 781 added one line |
|
| At line 783 added 2 lines |
| %%tab-Step9 |
| !!Step 9: messaggi, validazione "domain-level" e classi Validator |
| At line 786 added 149 lines |
| !masterLayout.xhtml (porzione) |
| %%prettify |
| {{{ |
| |
| [...] |
| |
| <div id="header"> |
| <h:graphicImage library="images" name="header_logo.gif"/> |
| JSF Sample Application #{applicationController.numeroRandom} |
| <div style="color:#770000;"> |
| <h:messages showDetail="false" globalOnly="true"/> |
| </div> |
| </div> |
| |
| [...] |
| |
| }}} |
| /% |
|
| !camera.xhtml (porzione) |
| %%prettify |
| {{{ |
| |
| [...] |
| |
| <h:message for="posti" style="color:red" /> |
| <h:panelGrid columns="2"> |
| <h:outputLabel for="nome" value="nome camera"/> |
| <h:inputText id="nome" value="#{listController.camera.nome}"/> |
| <h:outputLabel for="posti" value="posti letto"/> |
| <h:inputText id="posti" value="#{listController.camera.numeroPosti}" |
| validatorMessage="Il numero di posti deve essere compreso tra 1 e 5"> |
| <f:validateLongRange minimum="1" maximum="5"/> |
| </h:inputText> |
| |
| |
| }}} |
| /% |
|
|
| !ListController.java (porzione) |
| %%prettify |
| {{{ |
| |
| [...] |
| public String salvaPrenotazione() { |
| Prenotazione daSalvare = getPrenotazione(); |
| [...] |
| if (!verificaDisponibilita(daSalvare)) { |
| FacesContext.getCurrentInstance().addMessage(null, |
| new FacesMessage(FacesMessage.SEVERITY_ERROR, "Errore, la stanza non è disponibile nel periodo indicato","")); |
| return null; |
| } |
| [...] |
| } |
| |
| [...] |
| |
| private boolean verificaDisponibilita(Prenotazione daSalvare) { |
| boolean intersezione = false; |
| for (Prenotazione pre : prenotazioni) { |
| if (pre.getCamera().equals(daSalvare.getCamera())) { |
| if (pre.getDataFine().before(daSalvare.getDataInizio())) { |
| continue; |
| } else if (pre.getDataInizio().after(daSalvare.getDataFine())) { |
| continue; |
| } else { |
| intersezione = true; |
| } |
| } |
| } |
| return !intersezione; |
| } |
| |
| [...] |
| |
| }}} |
| /% |
|
| !CameraValidator.java |
| %%prettify |
| {{{ |
| /* |
| * To change this template, choose Tools | Templates |
| * and open the template in the editor. |
| */ |
|
| package corsojsf.managedbeans; |
|
| import corsojsf.model.Camera; |
| import javax.faces.application.FacesMessage; |
| import javax.faces.component.UIComponent; |
| import javax.faces.context.FacesContext; |
| import javax.faces.validator.FacesValidator; |
| import javax.faces.validator.Validator; |
| import javax.faces.validator.ValidatorException; |
|
| @FacesValidator(value="cameraValidator") |
| public class CameraValidator implements Validator{ |
|
| @Override |
| public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { |
| if (!(value instanceof Camera)) |
| throw new ValidatorException( |
| new FacesMessage("L'oggetto da passare a CameraValidator deve essere una camera")); |
| Camera camera= (Camera)value; |
| if (camera.getNumeroPosti()>2 && camera.getPrezzo().intValue() < 50) |
| throw new ValidatorException( |
| new FacesMessage("Le camere con più di 2 posti devono avere un prezzo > di 50")); |
| } |
|
| } |
|
|
| }}} |
| /% |
|
| !prenotazione.xtml (porzione) |
| %%prettify |
| {{{ |
|
| [...] |
|
| <h:selectOneMenu id="camera" value="#{listController.prenotazione.camera}"> |
| <f:selectItems value="#{listController.camere}" var="camera" itemValue="#{camera}" itemLabel="#{camera.nome}"/> |
| <f:validator validatorId="cameraValidator"/> |
| </h:selectOneMenu> |
|
| [...] |
|
| }}} |
| /% |
|
| /% |
| %%tab-Downloads |
| !!Downloads |
|
| ||Descrizione||File |
| | Sorgenti dell'esempio completo | [SmeaCrud-src.zip] |
| | War dell'applicazione web | [SmeaCrud.war] |
| | Slide del corso | [Corso JSF.ppt] |
|
|
|
| /% |
|
| /% |
|
| [appoggio] |