CSE446 Software Quality Management

Report
CSE446 SOFTWARE QUALITY
MANAGEMENT
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 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ş
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ş
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ş
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.somevalue eq 1}</if>
<to-view-id>greeting.xhtml</to-view-id>
<redirect/>
</navigation-case> CSE446 Software Quality Management
Spring 2014 – Orhan Başar Evren - Netaş
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:
<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ş
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"
<f:view locale=“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ş
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:
• <ui:insert>
• <ui:define>
• <ui:include>
• <ui:param>
• <ui:remove>
• <ui:composition>
CSE446 Software Quality Management
Spring 2014 – Orhan Başar Evren - Netaş
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ş
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ş
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:commandButton id=“clickbtn”
value=“Click Me” />
CSE446 Software Quality Management
Spring 2014 – Orhan Başar Evren - Netaş
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:commandButton onclick=“alert(‘test’);”/>
CSE446 Software Quality Management
Spring 2014 – Orhan Başar Evren - Netaş
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ş
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ş
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<UIComponent> componenets =
FacesContext.getCurrentInstance().getViewRoot().getChildren();
CSE446 Software Quality Management
Spring 2014 – Orhan Başar Evren - Netaş

similar documents