JBOSS Seam - VRSoft Dipl.

advertisement
A short overview
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
1
 Seam
is a web application framework based
on JavaServer Faces which aims to simplify
web development by reducing XML
configuration tasks
 Seam web applications can be deployed in
EJB3 containers but this is not a must
 Seam provides an embedded EJB3 container
 Seam does not need EJB3 features at all. It
works fine with POJO and JPA.
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
2
 This
presentation is not intended to provide
a full description of all the features available
in Seam.
 It is the authors intend to present the key
features and configuration hints
 For feedback please send mail to
seam@vrsoft.de
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
3
Seam
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
4
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
5
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
6
Or
• sacrifice
EJB support
• All Seam
features
available
• Security
• Pageflow
• Exception
handling
• Enhanced
JSF
Expression
Language
(JSF-EL)
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
Web container
• Use
embedded
EJB3
Java EE container
J2EE container
Decide on how your Seam application will be deployed
• Use
embedded
EJB3
Or
• sacrifice
EJB support
7
Seam
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
8
JBoss Seam
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
9
 Form



Backing Beans
Directly supported by JSF
The targets of JSF forms
Bring data into JSF pages
 Action



Listener
Target of form submission & links
Implementation of the MVC controller
Performing business logic
 Browser

Accessible Components
Accessing EJBs or POJOs via JavaScript (AJAX)
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
10
POJO
Stateless
Session
Bean
Statefull
Session
Bean
Entity
Bean
Message
Driven
Bean
Component
++
--
++
++
--
Backing Bean
++
++
++
--
--
Action Listener
--
++
++
--
--
Browser Comp.
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
11
Container
and your
Seam
Application
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
12
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
13
What needs to be done to get SEAM in place?
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
14
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
15
What needs to be done to get a Seam application running?
1.
Bundle Seam core libraries with your
application (ear or war)
2.
Configure Facelets
FaceletViewHandler (for basic Seam features)
SeamFaceletViewHandler (enhanced JSF-EL, security)
3.
Configure web application environment
Seam JSF Phase Listener
Seam Servlet Listener
4.
Configure Seam features (optional)
SeamFilter & Filter Mapping prepares Exception Handling &
Validation
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
16
What needs to be done to get a Seam application running?
5.
Configure EJB components
SeamEJBInterceptor
EJB Beans declarations (optional)
6.
Enable optional Seam components
Security
Pageflow
jBPM
7.
Define / Configure Behavior
Actions
Navigation
Error Handling
Conversation Management
Security
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
17
 If
you are developing a web application using
a war-archive then put jboss-seam.jar in
myapp/WEB-INF/lib directory
 If you are developing an enterprise
application (ear) then put jboss-seam.jar in
root of the EAR archive and reference the
jboss-seam.jar module as shown on the next
slide in your application.xml
Replace the highlighted regions according
with your application
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
18
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/application_5.xsd"
version="5">
<display-name>MyApp</display-name>
<module>
<web>
<web-uri>myapp.war</web-uri>
<context-root>/myapp</context-root>
</web>
</module>
<module>
<ejb>myapp-ejb.jar</ejb>
</module>
<!-- Seam and EL -->
<module>
<java>jboss-seam.jar</java>
</module>
</application>
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
19
 Put



JavaServer Faces (jsf-facelets.jar)
Expression Language API (el-api.jar
EL-Reference Implementation (el-ri.jar)
into your webapp classpath i.e. WEB-INF/lib
 Set

com.sun.facelets.FaceletViewHandler


view-handler in faces-config.xml to
If you want basic Facelet support
org.jboss.seam.ui.facelet.SeamFacletViewHandler

If you want enhanced features like JSF EL, validation,
security
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
20
 Seam
needs to register itself with JSF in
order to receive events during request
processing. Therfore we have to add a
SeamPhaseListener to faces-config.xml.
<faces-config>
…
<lifecycle>
<phase-listener>
org.jboss.seam.jsf.SeamPhaseListener
</phase-listener>
</lifecycle>
…
</faces-config>
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
21
 Seam
contexts and core services are
managed by a SeamServletListener which you
have to setup in web.xml.
<web-app>
…
<listener>
<listener-class>
org.jboss.seam.servlet.SeamListener
</listener-class>
</listener>
…
</web-app>
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
22
 Some
Seam features which can be configured
in components.xml need a basic web filter
 you
have to add the definitions shown on the
next slide to web.xml
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
23
<web-app> …
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.web.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
…</web-app>
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
24
 Validation
 multi-part
form submission
 Validation
 And
other features are only available when
jboss-seam-ui is in the classpath of the
webapp.
Therefore you have to put jboss-seam-ui.jar
into webapp/WEB-INF/lib directory.
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
25
 In
order to use Seam EJB components you
have to install the Seam EJB Interceptor
which is done your ejb-jar.xml file.
<ejb-jar>
…
<assembly-descriptor>
<interceptors>
<interceptor>
<interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
</interceptor>
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
…
</ejb-jar>
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
26
 Step
5 is a necessary prerequisite for this
step!
 Components.xml is used to configure Seam
components. Either predefined ones or your
own components.
 Typically you will only enable predefined
components like security here.
 Your own components are made accessible
via the @Name annotation in your source!
But if you like you can configure your
components here also.
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
27
 If
you are going with EJB 3.0 you have to
provide a JNDI pattern for the lookup of
these EJBs.
<components>
…
<component name=“org.jboss.seam.core.init”>
<property name=“jndiPattern”>myApp/#{ejbName}/local</property>
</component>
…
</components>


#{ejbName} will expand to your EJB’s name during
runtime
Make sure seam.properties is in your META-INF
directory. The file does not need to have contents
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
28
Behavior is specified in pages.xml which is
optional
 There are


Page actions


Page navigation



redirect to a page, show JSF message, end conversation
Manage conversation properties


Same as navigation rules in faces-config.xml
Since faces-config.xml is for Facelets page navigation
should be defined here for consistency
Error handling


Trigger activity before a page is invoked
Start, end
Security

declare security constraints on pages, roles, users
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
29
JBoss Seam
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
30
Contexts provide a mechanism for data access. Seam provides the
following contexts:
 Session
Spans the full HTTP-Session

 Application
Spans as long as the web application is running

 Request
Spans as long as the current HTTP-Request

 Page

Data belongs to the page
 Conversation

Spans across several HTTP-Requests
 Workspace

Spans several sessions (i.e. users) and conversations
(more like a business process)
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
31
Implicit
 are default
 each request is
wrapped in an implicit
conversation
Explicit
Java
pages.
xml
@Begin / @End
on method
Conversation.XXX
begin
end
join
nest
JSF
Page
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
@action=“#{conversation.XXXX}”
in <page>-Element
 f:param conversationPropagation
or
 @propagation in
seam:link-Element
3/23/2016
32
JBoss Seam
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
33
Restore
View
Apply
Request
Values
Determine target
view & create /
restore it
Update UI
components with
request data
Render
Response
Invoke
Application
Refresh the view
Run application
callbacks / action
listeners
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
Process
Validations
Run registered
validators
Update
Model
Values
Update managed
beans
34
JBoss Seam
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
35
 Seams
Pageflow uses JBoss’s jBPMs Process
Definition Language (jPDL)
 jPDL has a different syntax than BPEL
 jPDL can be used to describe pageflows
 jPDL is different from <navigation-rule>Syntax
 jPDL consists of



States
Events / Outcomes
Transitions
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
36
 Can
be mixed with JSF navigation
 By default disables “back” button
functionality
 Good for modal or wizard-driven UI flows
 Good separation of flow and UI
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
37

Add
<component class=“org.jboss.seam.core.Jbpm”>
<property name=“pageflowDefinitions”>
<value>flow_A.jpdl.xml</value>
<value>flow_B.jpdl.xml</value>
</property>
</component>
to components.xml

Put the flow file (*.jpdl.xml) into the web apps
classpath. For security reasons flows should be
stored in <webapp>/WEB-INF/classes
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
38
jPDL
JSF/Seam
State
A
JSF
View
A
Event E
Outcome X
ActionListener.actionMethod
Method return value
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
State
B
JSF
View
B
39
Seam
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
40
 Provided
as predefined component (identity)
 Delegates implementation to user-defined
class
 Supports declarative security settings

i.e. JRules (drools.jar)
 Fine-grained

security
Finest level is method & instance
 Needs
facelets
 Needs jboss-seam-ui.jar in classpath
 Needs SeamFaceletViewHandler
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
41
Pages
Components
Methods
<page …>
<restrict>
</restrict>
</page>
<page
login-required=“true”>
…
</page>
pages.xml
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
@Restrict annotation
in Java Code either on
class or individual method
*.java
3/23/2016
42
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
43
Seam
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
44
JSF
Page
JSF
Page
POJO
Facade
Session
EJB
POJO
Facade
Entity
EJB
Managed Bean
Session
EJB
JSF
Page
JSF
Page
Automatically wrapped
in Managed Bean
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
Entity
EJB
45
Seam Features
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
46
 Injection
allows passing information from
outside into an object
 Injection is executed typically once during
initialization of the object
 Bijection passes information into an object
and allows information to be exported from
an object
 Bijection happens whenever needed not only
at initialization time
 Bijections is controlled via @in / @out
annotations
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
47
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
48

Situation


JBoss 4.2.x and 5.x are using JSF Reference
Implementation (which is JSF 1.2) while 4.0.5 uses
Apache MyFaces
Solution
Make sure “MyFaces” listener
(org.apache.myfaces.webapp.StartupServletContextListener) is
commented out in the listener sections of web.xml
 Remove “el-ri.jar” and “el-api.jar” from
application.xml
 Make sure you are using the application and lifecycle
settings provided on the next slide. Please check the
namespace declaration and version attribute!

© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
49
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<application>
<el-resolver>org.jboss.seam.jsf.SeamELResolver</el-resolver>
</application>
<lifecycle>
<phase-listener>
org.jboss.seam.jsf.SeamPhaseListener
</phase-listener>
</lifecycle>
<!-- more configurations go here -->
</faces-config>
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
50
 Software


JBoss Seam http://labs.jboss.com/jbossseam
JBoss AS http://labs.jboss.com/jbossas
 Books


Practical JBoss Seam Projects, Jim Farley, Apress
JBoss Seam Simplicity and Power Beyond Java
EE, Michael Juntao Yuan & Thomas Heute,
Prentice Hall
© Dipl.-Inform. Volker Reichel, VRSoft, 2007
3/23/2016
51
Download