SlideServe
Menu
Preferences
© SlideServe · v2026

Java Server Faces

fola avatar
28 slides · 441 Views · 280 likes · Sep 02, 2014

Java Server Faces. Tomasz Nowak. Konspekt. Historia Wstęp Architektura JSF Składniki aplikacji JSF. Historia. 1. Serwlety 2. JSP 3. Struts. Wstęp. Projekt Sun Microsystems JSF - specyfikacja JSF 1.0 (2004-03-11) JSF 1.2 (2006-05-11) Połączenie Struts i Swinga. Architektura JSF.

Java Server Faces - slide 1
01 / 28Java Server Faces
1 / 17

Download Presentation

Java Server Faces
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

More Related Content

Presentation Transcript
  1. Java Server Faces Tomasz Nowak

  2. Konspekt • Historia • Wstęp • Architektura JSF • Składniki aplikacji JSF

  3. Historia 1. Serwlety 2. JSP 3. Struts

  4. Wstęp • Projekt Sun Microsystems • JSF - specyfikacja • JSF 1.0 (2004-03-11) • JSF 1.2 (2006-05-11) • Połączenie Struts i Swinga

  5. Architektura JSF • API do reprezentacji komponentów, zarządzania stanem, obsługi zdarzeń i walidacji • Biblioteki znaczników do opisu interfejsu użytkownika

  6. Składniki aplikacji JSF • Backing Beans • Strony JSP • Komponenety UI • Pomocnicze klasy po stronie serwera • Walidatory, obsługa zdarzeń oraz obsługa nawigacji • Plik konfiguracji zasobów

  7. Przykład – greeting.jsp

  8. Przykład – greeting.jsp

  9. Przykład – response.jsp

  10. Serwlet FacesServlet pełni funkcję kontrolera Pojedynczy punkt wejścia do aplikacji (web.xml) Konfiguracja poprzez plik faces-config.xml Kontroler JSF

  11. Backing Bean • Spełnia reguły JavaBeans • Właściwości i metody związane z komponentami użytkownika • Dodatkowo: - walidacja - obsługa zdarzeń - nawigacja

  12. Backing Bean public class UserNumberBean { Integer randomInt = null; Integer userNumber = null; String response = null; private long maximum = 0; private long minimum = 0; public UserNumberBean() { …} public String getResponse() {…} …

  13. Managed-bean (faces-config.xml)

  14. Strona JSF   <HTML xmlns="http://www.w3.org/1999/xhtml"xml:lang="en">   <HEAD> <title>Hello</title> </HEAD>   <%@ page contentType="application/xhtml+xml" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>   <%@ taglib uri="http:.//java.sun.com/jsf/core" prefix="f" %> <body> <f:view>    <h:form id="helloForm1">  … </h:form> </f:view> </body> </HTML>

  15. Strona JSF - omowienie <h2> Hi. My name is Lock. I'm thinking of a number from <h:outputText value="#{UserNumberBean.minimum}"/> to <h:outputText value="#{UserNumberBean.maximum}"/>. Can you guess it? </h2>

  16. Strona JSF - omówienie <h:inputText id="userNo" value="#{UserNumberBean.userNumber}" converterMessage="#{ErrMsg.userNoConvert}"> <f:validateLongRange minimum="#{UserNumberBean.minimum}" maximum="#{UserNumberBean.maximum}" /> </h:inputText> <h:commandButton id="submit" action="success" value="Submit" /> … <h:message id="errors1" for="userNo"/>

  17. Walidacja • Walidacja w metodzie BackingBeana • Niejawna walidacja automatyczna (atrybutu REQUIRED) • Predefiniowane walidatory ( f:validateLength, f:validateDoubleRange, f:validateLongRange) • Własne walidatory (implementujące interfejs Validator, rejestrowane w faces-config.xml)

  18. Komunikaty o błędzie Pliki *.properties ApplicationMessages.properties userNoConvert=The value you entered is not a number.

  19. Komunikaty o błędzie (faces-config) <application> <resource-bundle> <base-name> guessNumber.ApplicationMessages </base-name> <var>ErrMsg</var> </resource-bundle> </application>

  20. Komunikaty o błędzie <h:inputText id="userNo" label="User Number" value="#{UserNumberBean.userNumber}" converterMessage="#{ErrMsg.userNoConvert}"> ... </h:inputText>

  21. Nawigacja faces-config.xml <navigation-rule> <from-view-id>/greeting.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/response.jsp</to-view-id> </navigation-case> </navigation-rule> greeting.jsp <h:commandButton id="submit" action="success" />

  22. response.jsp response.jsp <h:outputText id="result" value="#{UserNumberBean.response}"/> UserNumberBean.java public String getResponse() { if ((userNumber != null) && (userNumber.compareTo(randomInt) == 0)) return "Yay! You got it!"; else return "Sorry, " + userNumber + " is incorrect.";

  23. Procedury obsługi zdarzeń • ActionListener • ValueChangeListener

  24. ActionListener <h:commandButton actionListener=”#bean.sideEffect}” Immediate=„true”/> public void sideEffect(ActionEvent event) { //np. aktywacja/deaktywacja innych //elementów formularza

  25. ValueChangeListener <h:commandButton value=‘Zaloguj’ disabled=”true”/> <h:selectBooleanCheckbox binding=”#{loginBean.selectBooleanCheckbox1}” id=”selectBooleanCheckbox” valueChangeListener=”loginBean.checkbox1Changed}” onchange=”submit()”/> Public void checkbox1Changed(ValueChangeEvent valueChangeEvent) { if(selectBooleanCheckbox1.isSelected()) commandButton1.setDisabled(false); FacesContext context = FacesContext.getCurrentInstance(); context.renderResponse();

  26. Internacjonalizacja (faces-config) <application> <message-bundle> com.sun.bookstore6.resources.ApplicationMessages </message-bundle> <resource-bundle> <base-name> com.sun.bookstore6.resources.CustomMessages </base-name> <var>customMessages</var> </resource-bundle> <locale-config> <default-locale>en</default-locale> <supported-locale>es</supported-locale> <supported-locale>de</supported-locale> <supported-locale>fr</supported-locale> </locale-config> </application>

  27. Internacjonalizacja <f:loadBundle var=” customMessages” /> String current = event.getComponent().getId(); FacesContext context =FacesContext.getCurrentInstance(); context.getViewRoot() .setLocale((Locale) locales.get(current));

  28. Źródła • http://java.sun.com/javaee/javaserverfaces/ - strona domowa • http://java.sun.com/javaee/5/docs/tutorial/doc/index.html - tutorial • http://wazniak.mimuw.edu.pl/index.php?title=AWWW-1st3.6-w11.tresc-1.0-toc – prezentacja o JSF