1 / 22

CSE446 Software Quality Management

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 JSF – (Part 2) Managed Beans Navigation Resource Bundles Common tags UIComponents. JSF – Managed Beans.

varian
Download Presentation

CSE446 Software Quality Management

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

Presentation Transcript


  1. CSE446 Software Quality Management Orhan Başar Evren Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi

  2. Today’s Overview • Quick Review of HTTP and Servlets • JSF – (Part 2) • Managed Beans • Navigation • Resource Bundles • Common tags • UIComponents CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  3. JSF – Managed Beans • Managed bean is a regular java bean managed by JSF framework • It is the “Model” of user interface component • JSF 1.2 : Registered using xml file, such as faces-config.xml • JSF 2.0 registered easily with @ManagedBeanannotation • JSF 2.2 allows to be registered by CDI using @Named annotation CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  4. JSF – Managed Beans @ManagedBean annotation has two optional attributes : • name : reference name of the bean. Default value: the name of the class • eager : flag to specify if the application scoped bean will be initialized on startup or on first request Default value: false @ManagedBean(name=“Hello”, eager=true) CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  5. JSF – Managed Beans - Scopes • @RequestScoped: Bean lives as long as the HTTP request-response lives. (default) • @ViewScoped : Bean lives as long as user is interacting with the same JSF view • @SessionScoped: Bean lives as long as the HTTP session lives. • @ApplicationScoped : Bean lives as long as the web application lives. • @CustomScopedand@NoneScoped CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  6. JSF – Managed Property @ManagedProperty annotation is used to inject other managed beans or resources from JSF container. @ManagedBean public class HelloBean { @ManagedProperty(“#{otherBean}”) private OtherBean other; // need getters and setters etc… } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  7. JSF – Page Navigation • Implicit Navigation : Navigate to pages from directly JSF pages or from managed beans • Conditional Navigation Rule: Define the navigation rules with faces-config.xml file. • Form based rules • If – else rules • Redirect (and Forward) CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  8. JSF – Implicit Navigation <h:form> <h:commandButton action="page2" value="Move to page2.xhtml" /> </h:form> OR public String gotoToPage2() { return "page2"; } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  9. JSF – Conditional Navigation Rule <navigation-rule> <from-view-id>hello.xhtml</from-view-id> <navigation-case> <from-action>#{helloBean.doGreeting}</from-action> <from-outcome>success</from-outcome> <to-view-id>greeting.xhtml</to-view-id> </navigation-case> </navigation-rule> OR <navigation-case> <if>#{helloBean.somevalueeq 1}</if> <to-view-id>greeting.xhtml</to-view-id> <redirect/> </navigation-case> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  10. JSF – Resource Bundles Resource bundles are used for text manipulation and Internationalization For better maintainability it is always recommended to put all text and messages into properties files. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  11. JSF – Resource Bundles Define in faces-config.xml file as following: <application> <locale-config> <default-locale>en</default-locale> <supported-locale>tr</supported-locale> </locale-config> <resource-bundle> <base-name>resources.messages</base-name> <var>msg</var> </resource-bundle> </application> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  12. JSF – Resource Bundles message_tr.propertiestext file : greeting = Merhaba greetuser = Merhaba {0} example.with.dot= noktakullanımına örnek From xhtml page: xmlns:f="http://java.sun.com/jsf/core" <f:viewlocale=“tr"> <h:outputText value=“#{msg.greeting}”/> <h:outputText value=“#{msgs[‘example.with.dot’]}”/> <h:outputFormat value=“#{msg.greetuser}”> <f:param value=“#{helloBean.username}”> </h:outputFormat> </f:view> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  13. JSF – Resource Bundles Or from managed bean when needed: @ManagedProperty("#{msg}") private ResourceBundle bundle; ... String greetmsg = bundle.getString(”greeting”); … CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  14. JSF – Common Tags Facelet Tags xmlns:ui="http://java.sun.com/jsf/facelets Used for templates: • <ui:insert> • <ui:define> • <ui:include> • <ui:param> • <ui:remove> • <ui:composition> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  15. JSF – Common Tags HTML Tags xmlns:h="http://java.sun.com/jsf/html Used for HTML output: • <h:outputText> • <h:inputText> • <h:inputTextarea> • <h:selectBooleanCheckbox> • <h:graphicImage> • <h:panelGrid> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  16. JSF – Common Tags Core Tags xmlns:f="http://java.sun.com/jsf/core Core JSF functionality: • <f:view> • <f:ajax> • <f:param> • <f:convertNumber> • <f:validateLength> • <f:actionListener> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  17. JSF – Common Tag Attributes • Id : identifier for a component • binding: reference to component instance • rendered: flag to set rendering • styleClass: css class name • value: value of the component • converter: converter class name • required: flag to set requirement • <h:commandButtonid=“clickbtn” value=“Click Me” /> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  18. JSF – DHTML Event Attributes • Allows to make JavaScript calls on specific events • onblur: element loses focus • onchange : element’s value changes • onclick: mouse clicked over the element • onfocus : element receives focus • onkeypress: key is pressed • onsubmit : form is submitted • <h:commandButtononclick=“alert(‘test’);”/> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  19. JSF – Tag Examples - ui:composition dialog.xhtml: <ui:composition> <h:outputText value=“#{message}” /> <h:commandButton type="submit" value=“OK" /> <h:commandButton type="reset" value=“Cancel" /> </ui:composition> dialog.taglib.xml: <facelet-taglib> <namespace>http://cse446.yeditepe.edu.tr/sample</namespace> <tag> <tag-name>dialog</tag-name> <source>com/components/dialog.xhtml</source> </tag> </facelet-taglib> web.xml: <context-param> <param-name>javax.faces.FACELETS_LIBRARIES</param-name> <param-value>/WEB-INF/dialog.taglib.xml</param-value> </context-param> CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  20. JSF – Tag Examples - ui:composition page.xhtml: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ytu="http://cse446.yeditepe.edu.tr/sample"> <h:body> <ytu:dialog message="Hello"></ytu:dialog> </h:body> </html> Output: CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  21. JSF – UIComponent • UIComponent is base class for all user interfaces components in JSF. • UIComponent instances are organized into a component tree under a UIViewRoot • Can be accessed from FacesContext instance CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  22. JSF – UIComponent • UIComponent is base class for all user interfaces components in JSF. • UIComponent instances are organized into a component tree under a UIViewRoot • Can be accessed from FacesContext instance • UIInput, UICommand, HtmlInputText, and many other… List<UIComponent> componenets = FacesContext.getCurrentInstance().getViewRoot().getChildren(); CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

More Related