130 likes | 304 Views
JBoss Seam. Presented by Andy Nguyen Truc Pham. What is JBoss Seam?. Created by Gavin King A lightweight framework for Java EE 5.0 Provides a consistent and easy programming model for enterprise web applications. Facilitates stateful web applications development.
E N D
JBoss Seam Presented by Andy Nguyen Truc Pham
What is JBoss Seam? • Created by Gavin King • A lightweight framework for Java EE 5.0 • Provides a consistent and easy programming model for enterprise web applications. • Facilitates stateful web applications development.
Core Components in A Web App. • JSP • Serves as the front end • May call beans • EJB • Server side component • Performs business logic • ORM • Converts objects to database entities • Persist to and query from databases
A HelloBean example • <jsp:useBean id="nameBean" class="mybeans.UserNameBean"> <jsp:setProperty name="nameBean" property="*" /> </jsp:useBean> • <HTML> <BODY> <H3> Hello <%= nameBean.getUserName() %> ! </H3> <P> The current time is <%= new java.util.Date() %>. Have a nice day! Please type in your user name: <P> <FORM METHOD=GET> <INPUT TYPE="text" NAME="username" SIZE=15> <INPUT TYPE="submit" VALUE="Enter name"> </FORM> <BODY> </HTML>
A Seam Hello World example • A user enters his/her name into a web form to say Hello to Seam • Seam saves name to database • Seam displays all the names of those who had said Hello to Seam
Create A Data Model @Entity@Name("person")public class Person implements Serializable {private long id;private String name;@Id @GeneratedValue public long getId() { return id;}public void setId(long id) { this.id = id; }public String getName() { return name; }public void setName(String name) {this.name = name;}}
Map the Data Model to A Web Form <h:form>Please enter your name:<br/><h:inputText value="#{person.name}" size="15"/><br/><h:commandButton type="submit" value="Say Hello"action="#{manager.sayHello}"/> <h:dataTable value="#{fans}" var="fan"><h:column><h:outputText value="#{fan.name}"/></h:column></h:dataTable> </h:form>
Manager Bean @Stateless@Name("manager")public class ManagerAction implements Manager {@In @Outprivate Person person;@Outprivate List <Person> fans; @PersistenceContextprivate EntityManager em;public String sayHello () {em.persist (person);person = new Person ();fans = em.createQuery("select p from Person p").getResultList();return null;}
Summary Seam simplifies web application development • Intergrate Java EE frameworks • Designed for stateful web applications • Promotes the use of POJO and less XML using bijection • Configuration by exception