450 likes | 551 Views
JavaServer Faces. Peter Norrhall. Internet - Möjliggöraren. Internet för användare. Internet för utvecklare. Det suger!!!. €. €. €. €. €. €. €. €. €. €. €. €. Bra för konsulter. Dåligt på lång sikt. Java. GUI. Data. Business. JavaServer Faces. EJB 3. JPA. GWT.
E N D
JavaServer Faces Peter Norrhall
Internet - Möjliggöraren JavaServer Faces
Internet för användare JavaServer Faces
Internet för utvecklare Det suger!!! JavaServer Faces
€ € € € € € € € € € € € Bra för konsulter JavaServer Faces
Dåligt på lång sikt JavaServer Faces
Java GUI Data Business JavaServer Faces EJB 3 JPA GWT JavaServer Faces
JavaServer Faces JavaServer Faces
Managed Beans SearchBean { ... private String searchInput public String search() { ... } } Managed Beans Action JavaServer Faces
Managed Beans SearchBean { ... String searchInput String search() { ... return ”result”; } } Navigering JavaServer Faces
Navigering JavaServer Faces
Demo JavaServer Faces
RestoreView Apply Request Values Process Events Process Validations Process Events Render Response Process Events Invoke Application Process Events Update Model Values UI Component Tree HtmlInputText HtmlMessage HtmlCommandButton HtmlForm UIViewRoot Restore View JavaServer Faces
RestoreView Apply Request Values Process Events Process Validations Process Events Render Response Process Events Invoke Application Process Events Update Model Values UI Component Tree HtmlInputText HtmlMessage HtmlCommandButton HtmlForm UIViewRoot Apply Request Values Multi* JavaServer Faces
RestoreView Apply Request Values Process Events Process Validations Process Events Render Response Process Events Invoke Application Process Events Update Model Values UI Component Tree Managed Beans SearchBean { ... String searchInput String search() { ... } } HtmlInputText HtmlMessage HtmlCommandButton HtmlForm UIViewRoot Process Validations <h:inputText id="email" value="#{UserRegistration.user.email}" validator="#{UserRegistration.validateEmail}" required="true"> </h:inputText> Multi* JavaServer Faces
RestoreView Apply Request Values Process Events Process Validations Process Events Render Response Process Events Invoke Application Process Events Update Model Values UI Component Tree Managed Beans SearchBean { ... String searchInput String search() { ... } } HtmlInputText HtmlMessage HtmlCommandButton HtmlForm UIViewRoot Update Model Values Multi* JavaServer Faces
RestoreView Apply Request Values Process Events Process Validations Process Events Render Response Process Events Invoke Application Process Events Update Model Values Invoke Application UI Component Tree Managed Beans Multi* SearchBean { ... List result String searchInput String search() { ... } } HtmlInputText HtmlMessage HtmlCommandButton HtmlForm UIViewRoot JavaServer Faces
RestoreView Apply Request Values Process Events Process Validations Process Events Render Response Process Events Invoke Application Process Events Update Model Values UI Component Tree HtmlInputText HtmlInputText HtmlInputText UIColumn UIColumn UIColumn HtmlDataTable UIViewRoot Render Response Managed Beans SearchBean { ... List result String searchInput String search() { ... } } JavaServer Faces
Nyheterna i JSF 1.2 < Jsp 2.1 < Jsf 1.2 JavaServer Faces
Unified EL • #{searchBean.inputString} - deferred • ${searchBean.inputString} – immediate • Implicita objekt (application, cookie, ...) • Operatorer (+.-,*,/,%,A?B:C,==,!=,...) • Uttryck (#{searchBean.search}) JavaServer Faces
Nyheter i Jsf 1.2 - Sammanfattning • http://java.sun.com/developer/technicalArticles/J2EE/jsf_12 JavaServer Faces
Verktyg NetBeans Exadel Studio Oracle JDeveloper JBuilder Java Studio Creator SAP Developer Studio IntelliJ IDEA BEA Workshop Websphere Studio JavaServer Faces
Komponentbibliotek • JSF • MyFaces Extensions • Apache Tobago/ADF Faces (Oracle) • ICEFaces • Netadvantage for JSF • BackBase • RichFaces (Ajax4JSF) JavaServer Faces
Förändra/skapa komponenter JavaServer Faces
RestoreView Apply Request Values Process Events Process Validations Process Events Render Response Process Events Invoke Application Process Events Update Model Values Förändra komponenter • Egenskaper • CSS <h:inputText id="email" value="#{UserRegistration.user.email}" validator="#{UserRegistration.validateEmail}" required="true"> </h:inputText> JavaServer Faces
Skapa en komponent JavaServer Faces
JSF och Ajax • Komponentbibliotek • Sun Blueprint AJAX components • Ajax4JSF • Seam Remoting JavaServer Faces
Ajax4Jsf – a4j:support JavaServer Faces
Ajax4Jsf – CommandButton <a4j:commandButton action="#{searchBean.handleSearch}” reRender=”tblSearchResult, txtSearchTerm” value="#{bundle['search.search']}" styleClass="html-text"/> JavaServer Faces
Ajax4Jsf • <a4j:commandLink> • <a4j:region> • <a4j:poll> • <a4j:outputPanel> JavaServer Faces
JSF Ramverk • Apache Shale vs JBoss Seam • Dialog Manager (Conversation) • Validation • Remoting (Ajax) • Clay (Non-Jsp) • ... JavaServer Faces
EJB 3 Managed Beans @Stateless @Name(”searchBean”) public class SearchBean implements Search{ @Out List <SearchResult> result; @In @Out String searchInput String search() { ... } } SearchBean { ... List result String searchInput String search() { ... } } JBoss Seam <h:commandButton action="#{searchBean.search}" value="#{bundle['search.search']}" styleClass="html-text"/> JavaServer Faces
@Annoteringar - Validering public class UserRegistrationBean { @NotNull @Email public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } } JavaServer Faces
Seam – Ajax Remoting @Local public interface Search { @WebRemote public String suggest(String name); } @Name(”search”) public class SearchAction implements Search { public String suggest(String name) { String suggestion = null; ... return suggestion; } } <script language=”javascript”> // get the remote Search var search = Seam.Component.getInstance(”search”); function suggest(name) { search.suggest(name, suggestCallback); } function suggestCallback(suggestion) { form.suggestion.value = suggestion; } </script> JavaServer Faces
JBoss Seam • Fogar samman JSF och EJB 3 (Web Beans) • @Annoteringar – Ut med XML-konfig • AJAX för en bättre värld • Conversation – Stöd för tillståndsfulla multipla ”konversationer” JavaServer Faces
Facelets JavaServer Faces
Facelets - Våga Vägra JSP! JavaServer Faces
Facelets - Mallbaserat template.css template.xhtml .top{ margin: 0px; padding: 0px; height: 58px; width: 770px; font: 20px Verdana, Tahoma, Arial text-decoration-none } .right { ... } .bottom { ... } .container { ... } top container right bottom JavaServer Faces
Produktkatalog <ui:composition template="/templates/catalog_template.xhtml"> category.xhtml catalog_template.xhtml Menu (top) <ui:insert name=”container”> container </ui:insert Branding (right) <ui:define name=”container"> ... <h:graphicImage value=”...”/> ... </ui:define> <ui:define name=”container"> ... <h:graphicImage value=”...”/> ... </ui:define> ShoppingCart/CompanyInfo (bottom) product.xhtml JavaServer Faces
Produktkatalog catalog_template.xhtml product.xhtml JavaServer Faces
Facelets – enklare att • Skapa egna komponenter • Skapa valideringsfunktioner • Skapa ”taggar” • Skicka parametrar mellan sidor • Exadel Studio JavaServer Faces
Prestanda JavaServer Faces
Cache is King <s:cache key=”art_93682” enabled=”true” <h:outputText value=”#{art.title}”/> <h:outputText value=”#{art.header}”/><h:outputText value=”#{art.body}”/> </s:cache> JavaServer Faces
JSF 2.0 • Web Beans JSR 299 - JBoss • Oracles JSR för att uttöka designtime stödet i GUIbyggare • http://www.jsfcentral.com/listings/A10880?link JavaServer Faces
Summering JavaServer Faces