论坛首页 Java企业应用论坛

JSF+EJB3架构实际项目

浏览 8849 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-02-23  
想用JSF1.2+EJB3做个项目,先画了个架构图,拿上来让各位指点指点,有何不妥之处。。
  • 描述: jsf1.2+ejb3
  • 大小: 34.5 KB
   发表时间:2008-02-23  
seam已经为你做好一切了,嘿嘿
0 请登录后投票
   发表时间:2008-02-23  
各位从EJB设计的角度分析下,这样行不行。。至于seam,它只是这两者的一个粘合剂。还是想先从JavaEE5的技术角度来完成一个项目。
0 请登录后投票
   发表时间:2008-02-27  
基本的结构是没错的,我不是很明白“显示对象”是用来做什么的
0 请登录后投票
   发表时间:2008-02-27  
In my point of view,this structure is not so good. In your pattern, you don't benifit a lot from EJB3 and JSF. It's just the same like using struts1, spring, hibernate.

The main reasons are as following:

1) “显示对象”(Is it like actionForm in Struts1?), VO and PO are not needed any more,and use POJOs(+Annotation) as EJB3 entity Bean,which could also be used as VO,and be passed to web layer.In JSF "managed beans" and JSPs( or xhtml),use these beans as JSf compoment value binding objects.

In some cases, we need add some wrapper classes which may wrap several POJOs(EJB3 entity beans) for conmunication between web layer and business logic layer.

2) In EJB3 Session Bean,"EntityManger" is used for data handling. You will soon find out that DAO layer seems unnecessary. Consider no DAO layer first,add it when absolutely needed in case very complex business logic.


In my previous project using JSF+EJB,put it simply,the pattern is "Facelets--> .xhtml--> managedBean-->EJB Session Bean--> EJB3 Entity Bean -> database".

we use POJOs(+some wrapper classes) 1)for page component binding(in jsp or .xhtml); 2)for data transfer(as VO)between layers;and 3)for data persistence(as PO). This dramatically reduces the code for data conversion.

0 请登录后投票
   发表时间:2008-02-28  
整个结构没有什么问题,挺清楚的,基本是现在大家都认可的一种方式,不过在实施的时候还需要把握的准确一些,有些问题需要注意,比如层次之间的清晰,如界面层的东西不要传递到后面去。还有就是JPA的设计了,很多基于类似于JPA的设计容易受先前的一些影响,比如走着走着就走向以前的SQL老路,等等这些。
0 请登录后投票
   发表时间:2008-02-28  
补充一点,这些年大家对EJB都不是非常关注,大家的注意力都被吸引到了Spring和Hibernate,我自己开发的一点感触,其实EJB本身还是很优秀,只是对于开发而言不太具有亲和力,写了不长的业务代码,但是一个Deploy就要等半天,所以做着做着容易丧失耐性。

最近有个想法,不过没有时间去做,因为spring和hibernate从功能上来讲,和EJB没有太大的差别,除却AOP外,spring的功能与EJB Stateless Session一样,Hibernate和CMP一样,由于这些技术都基于配置,而且基本的参数类型也比较相似,所以可以使用spring,hibernate进行开发,用EJB运行,spring和hibernate的配置文件是可以转换为EJB配置的,这样一方面可以利用spring和hibernate进行便捷的开发,同时还可以利用EJB的优异性能进行运行。
0 请登录后投票
   发表时间:2008-03-02  
fxy1949 写道
In my point of view,this structure is not so good. In your pattern, you don't benifit a lot from EJB3 and JSF. It's just the same like using struts1, spring, hibernate.

The main reasons are as following:

1) “显示对象”(Is it like actionForm in Struts1?), VO and PO are not needed any more,and use POJOs(+Annotation) as EJB3 entity Bean,which could also be used as VO,and be passed to web layer.In JSF "managed beans" and JSPs( or xhtml),use these beans as JSf compoment value binding objects.

In some cases, we need add some wrapper classes which may wrap several POJOs(EJB3 entity beans) for conmunication between web layer and business logic layer.

2) In EJB3 Session Bean,"EntityManger" is used for data handling. You will soon find out that DAO layer seems unnecessary. Consider no DAO layer first,add it when absolutely needed in case very complex business logic.


In my previous project using JSF+EJB,put it simply,the pattern is "Facelets--> .xhtml--> managedBean-->EJB Session Bean--> EJB3 Entity Bean -> database".

we use POJOs(+some wrapper classes) 1)for page component binding(in jsp or .xhtml); 2)for data transfer(as VO)between layers;and 3)for data persistence(as PO). This dramatically reduces the code for data conversion.



我说的显示对象就是类似Struts的ActionFrom的东西。
很是受你的启发。我也一直觉得这样设计太过复杂,而且走入了SSH的圈套,大量的Bean的创建,属性挎贝执行效率会受影响。我目前新的设计见附图。也像你说的:Facelets --> ManagedBean -->EJB3 SessionBean(业务层) -->JPA (持久层) ---> DataBase(EIS层).这样就把Dao层去了,把VO和PO合并了,但感觉显示层的显示对象还是需要的,要不然有些数据在页面显示会有麻烦(robbin很早的一个帖子就讨论过这个问题)。请指点。。。
  • 描述: jsf+ejb3_diagram
  • 大小: 32.2 KB
0 请登录后投票
   发表时间:2008-03-03  

"但感觉显示层的显示对象还是需要的,要不然有些数据在页面显示会有麻烦"

I think if you have tried JSF a little bit, you will find out that how easy and well JSF handles this matter.

1) In Jsp(or xhtml) pages,the jsf components look like following:

<div class="light col input-field">
     <h:inputText id="mediaName" value="#{mediaBean.media.name}" size="50" maxlength="50" required="true"/>
</div>
 <div class="light col output-field">
      <h:outputText id="mediaComments" value="#{mediaBean.media.comments}"/>
 </div>

<div class="light col input-field">
     <h:selectOneMenu id="format" value="#{mediaBean.media.format.id}" validator="#{mediaBean.validateSelection}" required="true">
          <f:selectItems value="#{mediaBean.tapeFormatList}"/>
     </h:selectOneMenu>
/div>

mediaBean: JSF managed Beans

media: Pojo(+annotation),entity bean

name,comments,format: properties of Entity bean "Media"

 

tapeFormatList: List<SelectItem>

 

2) JSF managed bean examples:

 

public class MediaBean extends CmmManagedBean
{
static final Logger log=Logger.getLogger("MediaBean");

private Media media;

private List tapeSegmentList;

private boolean validAssetFlag;
private boolean validMediaFlag;
private boolean editFlag;
private int labelOffset;
......

}

 

3) Entity Bean

 

package uk.co.ondemand.cmm.service.persistence;

import java.util.Date;
import javax.persistence.*;

@Entity
@Table(name = "CMM_MEDIA_ASC")

 

public class Media extends GenericEntity
{
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ")
    @SequenceGenerator(name="SEQ", sequenceName="asset_container_id", allocationSize=1)
    @Column(name = "ID", nullable = false)
    protected long id;

    @Column(name = "CONTAINER_TYPE", nullable = false,insertable=false, updatable=false)
    private String containerType;

    @Column(name = "NAME", nullable = false)
    private String name;

 

@Column(name = "COMMENTS")
    private String comments;

 

@JoinColumn(name = "FORMAT", referencedColumnName = "ID")
    @ManyToOne
    private CmmEnumeration format=new CmmEnumeration();

 

@Transient 

private List foldersList;

//use "Transient" annotion for additional fields not persistent,but used in JSF component value binding for carrying data.

 

.....


    /** Creates a new instance of Media */
    public Media() {
    }
 
    /**
     * Gets the id of this AssetContainer.
     * @return the id
     */
    public long getId() {
        return this.id;
    }

    /**
     * Sets the id of this AssetContainer to the specified value.
     * @param id the new id
     */
    public void setId(long id) {
        this.id = id;
    }

 .....

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

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

    public CmmEnumeration getFormat() {
        return this.format;
    }

    public void setFormat(CmmEnumeration format) {
        this.format = format;
    }
   ......
}
 

4) You also can use converters for some data type conversion  between pages to models

 

faces-config.xml

...

<converter>

<converter-for-class>java.lang.Boolean</converter-for-class>
  <converter-class>uk.co.ondemand.cmm.web.jsf.YesNoBooleanConverter</converter-class>
 </converter>
 <converter>
  <converter-for-class>java.util.Date</converter-for-class>
  <converter-class>uk.co.ondemand.cmm.web.jsf.CmmDateTimeConverter</converter-class>
 </converter>
 <converter>
  <converter-for-class>java.sql.Timestamp</converter-for-class>
  <converter-class>uk.co.ondemand.cmm.web.jsf.CmmDateTimeConverter</converter-class>
 </converter>
.....

<managed-bean>
  <managed-bean-name>mediaBean</managed-bean-name>
  <managed-bean-class>uk.co.ondemand.cmm.web.managedbean.MediaBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>

 

 

Hope this is helpful.

 

0 请登录后投票
   发表时间:2008-03-04  
呵呵,我对JSF不是很了解,只是用JSF做过两个项目,以前都是用JSF+Spring+Hibernate。
如果用你说的PO一对象从持久层传到页面,就有一个这样的问题,我做一个员工的查询,我的员工PO类中只有入职时间,我现在要做个组件条件查询在某个时间段入职的员工,这里是不是得再构造个类似ActionForm对象了。请指教。。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics