250 likes | 436 Views
CSE446 Software Quality Management. Orhan Ba şar Evren. Spring 2014. Yazılım ve Uyguluma Geliştirme Yöneticisi. Today’s Overview. Quick Review of HTTP and Servlets JSP and JSTL JSP Overview Code Samples JSP Lifecycle Common JSTL Tags JSF – (Part 1) JSF Overview JSF Components
E N D
CSE446 Software Quality Management Orhan Başar Evren Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi
Today’s Overview • Quick Review of HTTP and Servlets • JSP and JSTL • JSP Overview • Code Samples • JSP Lifecycle • Common JSTL Tags • JSF – (Part 1) • JSF Overview • JSF Components • JSF Lifecycle CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSPJava Server Pages CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSP – Java Server Pages • JSP is a technology for developing dynamic and static web pages. • <% Java Code %> in HTML page • High level abstraction of Java Servlets • A servlet for each JSP at runtime CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSP – Sample Code <html> <body> <h1> Hello <% java.util.Date date = new java.util.Date(); out.print("from JSP"); %> </h1> Current date is : <%= date %> </body> </html> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSP – Java Server Pages CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSP – Auto generated Servlet Code out.write("<html>\n"); out.write(" <body>\n"); out.write(" <h1>\n"); out.write(" Hello \n"); java.util.Datedate = new java.util.Date(); out.print("from JSP"); out.write(" </h1>\n"); out.write(" </br>\n"); out.write(" Current date is : "); out.print( date ); out.write("\n"); out.write(" </body>\n"); out.write("</html>\n"); CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSTL – JSP Standard Tag Library • Java ServerPages Standard Tag Library • Extends the JSP Specification for adding tab library for common tags : • Data access • Data Process • Logical conditions and loops • Internationalization • Many other <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSTL – JSP Standard Tag Library • Some Core Tags : • <c:set></c:set> • <c:if> </c:if> • <c:forEach> </c:forEach> • <c:catch></c:catch> • <c:import></c:import> • Usage Examples: • <c:setvar="foo" scope="session" value="..."/> • <c:if test="${!empty param.Add}"> …. </c:if> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSTL – JSP Standard Tag Library • Some InternationalizationTags : • <fmt:formatNumber/> • <fmt:formatDate/> • <fmt:setLocale/> • <fmt:message> • </fmt:message> • Usage Examples: • <fmt:message key=“username_label"/> • <fmt:formatNumber value="${book.price}" type="currency"/> • <fmt:formatDate value="${now}" type="date“/> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSTL – JSP Standard Tag Library • Some SQL Tags : • <sql:setDataSource/> • <sql:query/> • <sql:transaction/> • <sql:update> • Usage Examples: • <sql:setDataSourcedataSource="jdbc/BookDB" /> • <sql:queryvar="books" > select * from books</sql:query> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSTL – JSP Standard Tag Library • Some Functions : • <fn:length/> • <fn:toUpperCase/> • <fn:substring/> • <fn:replace/> • Usage Examples: • <c:if test="${fn:length(param.username) > 0}" > … • <c:setvar=“str2" value="${fn:substring(str1, 5, 15)}" /> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSP – Custom Tags public class HelloTag extends SimpleTagSupport{ public void doTag() throws JspException, IOException { JspWriterout = getJspContext().getOut(); out.println("Hello Custom Tag!"); } } • Define TDL file (XML defination file not listed here) • Usage Examples: • <%@ taglib prefix="ex" uri="WEB-INF/custom.tld"%> • <ex:Hello> </ex:Hello> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSP - deprecated ? JSP is considered "deprecated" as of the Java Enterprise Edition and replaced by JSF. However, it is still commonly used: • Default view technology of Spring MVC • Google cloud App Engine: JSP interface support • Possible to combine with JSF • Many other applications exists Because it is supported with all Java Web Servers, while JSF is supported by Java EE compliant web servers. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSFJava Server Faces CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Java Server Faces • Server side user interface component framework • JSF is specification for a web application development framework • MVC based pattern : Better separation of behavior and presentation • Built-in component model • Facelets: reusable and extendable CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Java Server Faces CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Java Server Faces CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Java Server Faces • API Specification: JSF 2.2 (contains standard components) • Major Implementations: • Oracle Mojarra • Apache MyFaces • Major Componenet Libraries: • RichFaces, PrimeFaces, ICEFaces, etc. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Java Server Faces • Primefaces’ component examples CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Life Cycle • Handling incoming requests • Decoding parameters • Modifying and saving state • Rendering web pages to the browser JSF framework manages lifecycle phases automatically, however it also allows to monitor and manage phases manually CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Life Cycle CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Life Cycle • Restore View Phase :builds the view of the page, wires events and components and saves the view in FacesContext • Apply Request Values Phase:new (local) values of the components are set by request parameters • Process Validations Phase: values of the components are validated by rules • Update Model Values Phase:Sets local values of the components to server-side object • Invoke Application Phase:handling application level events like form submitting, linking, redirecting etc. • Render Response Phase:building the view and rendering the page CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF - Life Cycle - Monitor public class LifeCycleListener implements PhaseListener{ public PhaseIdgetPhaseId() { return PhaseId.ANY_PHASE; } public void beforePhase(PhaseEvent event) { System.out.println(“BEFORE " + event.getPhaseId()); } public void afterPhase(PhaseEvent event) { System.out.println(“AFTER " + event.getPhaseId()); } } faces-config file: <lifecycle> <phase-listener>package.LifeCycleListener</phase-listener> </lifecycle> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
Images are referenced from http://docs.oracle.com/javaee/7/tutorial/doc/home.htm CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş