There are many useful templates that you can use.
Traditional approach
view >> controller >> service >> domain
What can be translated into
<h:commandButton value="Deposit" action="#{accountController.removeAccount(account)}"/> @Name("accountController") public class AccountController implements Serializable { private @In AccountService accountService; public void removeAccount(Account account) { accountService.removeAccount(account); } } @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> { }
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