JBoss Seam Design Templates?

I really liked the JBoss Seam application framework. Since the concept of injection / release and tight integration between JSF / EJBs / JPA is relatively limited among Java application frameworks, I searched for some good resources for design patterns and best practices for using this structure. I poured examples and several books on this subject. However, I'm more interested in real-world models that compare with traditional J2EE design patterns. For example, traditional DAO or EntityHome / EntityQuery. Where should the business logic be executed? In Action classes? Or in specialized service classes? I would really appreciate the understanding Seam developers can give. Thanks!

+6
design jpa jsf seam ejb
source share
1 answer

There are many useful templates that you can use.

Traditional approach

view >> controller >> service >> domain 

What can be translated into

 /** * view */ <h:commandButton value="Deposit" action="#{accountController.removeAccount(account)}"/> /** * controller */ @Name("accountController") public class AccountController implements Serializable { /** * Usually a plain POJO or EJB */ private @In AccountService accountService; public void removeAccount(Account account) { accountService.removeAccount(account); } } /** * service */ @Name("accountService") public class AccountServiceImpl implements AccountService { private @In EntityManager entityManager; public void removeAccount(Account account) { entityManager.remove(account); } } 

If you have several actions that you need to manage server-side JSF components , using a controller as shown above might be a good idea

You can also use

 view >> service >> domain 

This is basically the same approach shown above , but without a controller

Or using the built-in reseller template using EntityHome / EntityQuery

 view >> domain 

Register your EntityHome as follows / WEB -INF / components.xml

 <framework:entity-home name="accountHome" entity-class="br.com.ar.seam.Account"/> 

Now you can create an alias using the factory element

 <factory name="account" value="#{accountHome.instance}"/> /** * view * * Notice account will be evaluated as accountHome.instance */ <h:commandButton value="Deposit" action="#{account.remove}"/> 

Nothing else. Keep in mind that when using any EntityHome (JPA) or HibernateEntityHome (Hibernate) object, you usually need to override some methods. To improve performance as follows

 @Name("accountHome") public class AccountHome extends EntityHome<Account> { /** * Override any method you want right here */ } 

About business logic ??? You can put it at your service level or use a domain-based approach. See here which is best for you.

Testing: Use seam-related testing components. Take a look at the Seam sample catalogs. To get an overview of how you can perform testing without deployment

If possible, use the seam-gen command. To create a project. The Seam book in the action book, chapter 2, can give a good idea of ​​how to run seam-gen functions. read carefully . Any project created by seam-gen can be opened and tested in NetBeans and Eclipse

JSF components: look here

There is more: don't use @ Out-jection anymore. Use @ Factory instead. @ Out-jection will be deprecated in favor of the @Factory method.

I think that queries are better stored inside an external file, because

  • It is readable
  • Supported by

Properly

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <query name="GIFT_CARDS_WITH_BUYER"> <![CDATA[ from GiftCard c left join fetch c.buyer where c.recipientNotificationRequested = 1 ]]> </query> <query name="GIFT_CARDS_WITHOUT_NO_RELATIONSHIP"> <![CDATA[ from GiftCard ]]> </query> </hibernate-mapping> 

Good not

Another resource goes here (pdf format)

JBoss Seam: Agile RIA Development Framework

+8
source share

All Articles