Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
SWPITutorium
WebApplica4on• WebApplica4on(Oracle.com)
DB
DB
JavaServerFaces(hGps://en.wikipedia.org/wiki/JavaServer_Faces)• AJavaspecifica4onforbuildingcomponent-baseduserinterfacesforwebapplica4ons
www.irian.at
• JSF2usesFaceletsastempla4ngsystem• ServletEngine– Processesrequests– Loadstheappropriateviewtemplate– Buildsacomponenttree– Processesevents– Renderstheresponsetotheclient
• ThestateofUIcomponentsandotherobjectsofscopeissavedattheendofeachrequest
• Thestateoftheviewwillberestoreduponnextcrea4on
Facelets(hGp://docs.oracle.com/javaee/6/tutorial)
• Theviewdeclara4onlanguageforJavaServerFacestechnology
• Thepreferredpresenta4ontechnologyforbuildingJavaServerFacestechnology-basedapplica4ons
• Faceletsfeatures– UseofXHTMLforcrea4ngwebpages– SupportforFaceletstaglibraries– SupportfortheExpressionLanguage(EL)– Templa4ngforcomponentsandpages
ExpressionLanguage(EL)• Animportantmechanismforthecommunica4onbetweenpresenta4onlayer(webpages)andapplica4onlogic(managedbeans)
• Func4ons– evalua4onofexpressions– setandgetdata,and– invokemethods
• Examples– <h:bodyrendered="#{!loginBean.isLoggedIn()}">– <h:inputTextid="username"value="#{loginBean.username}"required="true"requiredMessage="DerBenutzernamedarfnichtleersein."/>
Glassfish
• GlassFishServerprovidesaserverforthedevelopmentanddeploymentofJavawebapplica4ons.
• Func4onsofGlassFishServer4.0– Alightweightandextensiblecore– AwebcontainertointeractwithJavaservlets– Supportforhighavailabilityclusteringandloadbalancing– Aneasy-to-useAdministra4onConsoleforconfigura4onandmanagement
– UpdateToolconnec4vityforupdatesandadd-oncomponents
• f:thecoreJavaServerFacescustomac4onsthatareindependentofanypar4cularrender– f:convertDateTime,e.g.
<f:convertDateTimepaGern="dd.MM.yyyy"/>– f:validateRegex,e.g.
<f:validateRegexpaGern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]"/>
TagLibrariesandExamples(hGp://docs.oracle.com/javaee/6/javaserverfaces/2.1/
docs/vdldocs/facelets/)
• ExamplefromhGp://www.jskoolbox.com– JSF–File:date4me.xhtml
<?xmlversion='1.0'encoding='UTF-8'?><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transi4onal//EN”"hGp://www.w3.org/TR/xhtml1/DTD/xhtml1-transi4onal.dtd"><htmlxmlns="hGp://www.w3.org/1999/xhtml" xmlns:f="hGp://java.sun.com/jsf/core"xmlns:h="hGp://java.sun.com/jsf/html"><body><f:view><h:outputTextvalue="#{dateBean.today}"> <f:convertDateTimedateStyle="full"4meZone="EST"type="date"/></h:outputText></f:view></body></html>
– Javacode:DateBean.java
– HTMLoutput
importjava.u4l.Date;importjavax.faces.bean.ManagedBean;importjavax.faces.bean.RequestScoped;//JSF2managedbeanfordatehandling.@ManagedBean@RequestScopedpublicclassDateBean{publicDategetToday(){returnnewDate();}}
• h:JavaServerFacescomponenttagsforallUIComponent+HTMLRenderer– h:commandBuGon,e.g.<h:commandBuGonac4on="#{helloWorld.english}" value="EN"/>
– h:link,e.g.<h:linkvalue="Back"outcome="helloworld.xhtml"/>
– H:outputText,e.g.,<h:outputTextvalue="#{dateBean.today}“>
HelloWorldExample
JavaHelloWorld.java
Viewshelloworld.xhtmlenglish.xhtmlgerman.xhtml
Viewconfigurea4onFaces-config.xml
web.xml
• ui:addingtempla4ng,e.g.– template.xhtml(fromhGp://www.jskoolbox.com)<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transi4onal//EN""hGp://www.w3.org/TR/xhtml1/DTD/xhtml1-transi4onal.dtd"><htmlxmlns="hVp://www.w3.org/1999/xhtml"xmlns:h="hVp://java.sun.com/jsf/html"xmlns:ui="hVp://java.sun.com/jsf/facelets"><h:head><4tle><ui:insertname="\tle"/></\tle></h:head><body><h2><ui:insertname="header"/></h2><ui:insertname="message"/></body></html>
– date4meTemplate.xhtml<body>
<ui:composi4ontemplate="template.xhtml"><ui:definename="\tle">Welcome</ui:define><ui:definename="header">Thedateoftodayis</ui:define><ui:definename="message"><h:outputTextvalue="#{dateBean.today}"> <f:convertDateTimedateStyle="full"\meZone="EST"type="date"/></h:outputText></ui:define></ui:composi4on></body></html>