JBoss Seam Presented by Andy Nguyen Truc Pham. What is JBoss Seam? Created by Gavin King Created by...

Post on 30-Dec-2015

216 views 3 download

Tags:

Transcript of JBoss Seam Presented by Andy Nguyen Truc Pham. What is JBoss Seam? Created by Gavin King Created by...

JBoss SeamJBoss Seam

Presented byPresented by

Andy NguyenAndy NguyenTruc PhamTruc Pham

What is JBoss Seam?What is JBoss Seam?

• Created by Gavin King Created by Gavin King

• A lightweight framework for Java EE 5.0A lightweight framework for Java EE 5.0

• Provides a consistent and easy programming Provides a consistent and easy programming model for enterprise web applications.model for enterprise web applications.

• Facilitates stateful web applications Facilitates stateful web applications development.development.

Core Components in A Web Core Components in A Web App.App.• JSP JSP

•Serves as the front endServes as the front end

•May call beansMay call beans

• EJBEJB•Server side componentServer side component

•Performs business logicPerforms business logic

• ORMORM•Converts objects to database entitiesConverts objects to database entities

•Persist to and query from databasesPersist to and query from databases

A HelloBean exampleA HelloBean example• <jsp:useBean id="nameBean" <jsp:useBean id="nameBean"

class="mybeans.UserNameBean"> <jsp:setProperty class="mybeans.UserNameBean"> <jsp:setProperty name="nameBean" property="*" />name="nameBean" property="*" />

</jsp:useBean></jsp:useBean>

• <HTML> <HTML> <BODY> <BODY> <H3> Hello <%= nameBean.getUserName() %> ! </H3> <H3> Hello <%= nameBean.getUserName() %> ! </H3> <P> The current time is <%= new java.util.Date() %>. Have a nice day! <P> The current time is <%= new java.util.Date() %>. Have a nice day!

Please type in your user name: <P> Please type in your user name: <P> <FORM METHOD=GET> <FORM METHOD=GET> <INPUT TYPE="text" NAME="username" SIZE=15> <INPUT TYPE="text" NAME="username" SIZE=15> <INPUT TYPE="submit" VALUE="Enter name"> <INPUT TYPE="submit" VALUE="Enter name"> </FORM> </FORM> <BODY><BODY> </HTML></HTML>

A Seam Hello World A Seam Hello World exampleexample

• A user enters his/her name into a web A user enters his/her name into a web form to say Hello to Seamform to say Hello to Seam

• Seam saves name to databaseSeam saves name to database

• Seam displays all the names of those Seam displays all the names of those who had said Hello to Seamwho had said Hello to Seam

Create A Data ModelCreate A Data Model

@Entity@Entity@Name("person")@Name("person")public class Person implements Serializable {public class Person implements Serializable {

private long id;private long id;private String name;private String name;

@Id @GeneratedValue@Id @GeneratedValue

public long getId() { return id;}public long getId() { return id;}public void setId(long id) { this.id = id; }public void setId(long id) { this.id = id; }

public String getName() { return name; }public String getName() { return name; }public void setName(String name) {this.name = name;}public void setName(String name) {this.name = name;}} }

Map the Data Model to A Web Map the Data Model to A Web FormForm

<h:form><h:form>Please enter your name:<br/>Please enter your name:<br/><h:inputText value="#{person.name}" <h:inputText value="#{person.name}" size="15"/><br/>size="15"/><br/><h:commandButton type="submit" value="Say <h:commandButton type="submit" value="Say Hello"Hello"action="#{manager.sayHello}"/>action="#{manager.sayHello}"/><h:dataTable value="#{fans}" var="fan"><h:dataTable value="#{fans}" var="fan"><h:column><h:column><h:outputText value="#{fan.name}"/><h:outputText value="#{fan.name}"/></h:column></h:column></h:dataTable> </h:dataTable> </h:form> </h:form>

Manager BeanManager Bean@Stateless@Stateless@Name("manager")@Name("manager")public class ManagerAction implements Manager {public class ManagerAction implements Manager {

@In @Out@In @Outprivate Person person;private Person person;

@Out@Outprivate List <Person> fans; private List <Person> fans; @PersistenceContext@PersistenceContextprivate EntityManager em;private EntityManager em;

public String sayHello () {public String sayHello () {em.persist (person);em.persist (person);person = new Person ();person = new Person ();fans = em.createQuery("select p from Person p")fans = em.createQuery("select p from Person p").getResultList();.getResultList();

return null;return null;} }

SummarySummary

Seam simplifies web application development Seam simplifies web application development

• Intergrate Java EE frameworksIntergrate Java EE frameworks

•Designed for stateful web applicationsDesigned for stateful web applications

•Promotes the use of POJO and less XML using bijectionPromotes the use of POJO and less XML using bijection

•Configuration by exceptionConfiguration by exception