Transcript CSE446 Software Quality Management
CSE446 S
OFTWARE
Q
UALITY
M
ANAGEMENT
Orhan Başar Evren Yazılım ve Uyguluma Geliştirme Yöneticisi Spring 2014
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ş
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 @ManagedBean annotation – JSF 2.2 allows to be registered by CDI using @Named annotation CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
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ş
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. – @CustomScoped and @NoneScoped CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF – Managed Property
@ManagedProperty inject other managed beans or resources from JSF container.
annotation is used to } @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ş
JSF – Page Navigation
–
Implicit Navigation
pages from directly JSF pages or from managed beans : Navigate to –
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ş
JSF – Implicit Navigation
OR
} public String gotoToPage2() { return "page2"; CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
JSF – Conditional Navigation Rule
OR
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ş
JSF – Resource Bundles
Define in faces-config.xml file as following:
JSF – Resource Bundles
message_tr.properties text file : greeting = Merhaba greetuser = Merhaba {0} example.with.dot = nokta kullanımına örnek
From xhtml page:
xmlns:f="http://java.sun.com/jsf/core"
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ş
JSF – Common Tags
Facelet Tags
xmlns:ui="http://java.sun.com/jsf/facelets • • • • • •
Used for templates:
JSF – Common Tags
HTML Tags
xmlns:h="http://java.sun.com/jsf/html • • • • • •
Used for HTML output:
JSF – Common Tags
Core Tags
xmlns:f="http://java.sun.com/jsf/core • • • • • •
Core JSF functionality:
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 •
• • • • • •
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 •
JSF – Tag Examples - ui:composition
dialog.xhtml:
dialog.taglib.xml:
web.xml:
JSF – Tag Examples - ui:composition
page.xhtml:
Output:
CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş
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ş
•
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
CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş