如何改善这种设计,该设计从基于JSF的前端调用第三方方法 [英] How can I improve this design that calls third party methods from JSF based front end

查看:148
本文介绍了如何改善这种设计,该设计从基于JSF的前端调用第三方方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关设计的意见和专家建议.

I want opinions and expert advice on design .

我正在使用JSF2和EJB3开发应用程序,而不是使用CDI.

I am developing an application using JSF2 and EJB3 and I am not using CDI.

我已经从另一个团队获得了一个API(jar),其中有三种主要方法.一个人搜索数据库并返回汽车列表,一个人返回手推自行车列表,一个人返回船列表.
因此,基本上,我们有三种不同的车辆清单.

在ui端,用户有一个搜索表单,其中包含三个单选按钮,分别用于用户要搜索的每种类型的车辆,例如,用于汽车,手推单车或轮船的Radio.然后在同一页面上,我们可以看到三个单独的部分用户可以在其中提供有关要搜索的内容的详细信息.例如,如果用户想要汽车列表,则可以选择提供注册号或制造型号等,并且如果用户要搜索船只,则可以在其中输入字段以提供名称的详细信息
有一个搜索按钮.现在我想建议如何最好地放置图层以访问此jar,以便进行调用并显示结果.
以下是我的处理方法
我有一个SearchBean是JSF管理的bean.
我有三个类CarSearchRequestPushBikeSearchRequestBoatSearchRequest每个都有一个search()方法.
然后我有三个无状态会话bean CarDAOPushBikeDAOBoatDAO这些DAO中的每一个都调用给定jar中的方法,例如CarDAO将调用返回car的API,依此类推.
上面的三个Request类中的每个都有一个私有的默认构造函数,只有public构造函数将各自的DAO作为参数.
然后在注入三个DAO EJB之后在SearchBean中,并在@PostConstruct方法中初始化所有三个Request对象并将DAO传递给它们的构造函数.
然后,屏幕上的搜索按钮将调用searchBean的search()方法,就像这样

I have been given an API (jar) from an other team and there are three main methods in it. One searches the database and returns a list of cars and one returns a list of pushbikes and one returns list of boats.
So basically we have three different lists of different vehicles.

At the ui side user has a search form with three radio buttons one for each type of vehicle that user wants to search for i.e Radio for car,pushbike or boat.Then one the same page we have three separate sections all visible to user where user can provide details as to what is to be searched.e.g if user wants a list of cars there is option to provide registration number or make model etc and if user wants to search for boats input fields are there to provide details for name of boat or marina etc.
There is one search button.Now I want advice of how to best put the layers to access this jar make the call and show results.
Following is how I am approaching it
I have a SearchBean which is JSF managed bean.
I have three classes CarSearchRequest , PushBikeSearchRequest and BoatSearchRequest each of them has a search() method.
Then I have three stateless session beans CarDAO , PushBikeDAO and BoatDAO each one of these DAO makes the call to method in given jar e.g. CarDAO will make call to API that returns car and so on .
Each of the three Request classes above has a private default constructor and only public constructor takes a respective DAO as an argument .
Then in my SearchBean after I am injecting three DAO which are EJBs and in @PostConstruct method I am initialising all three Request objects and passing the DAO to their constructors.
The search button on Screen then calls the search() Method of searchBean which is something like this

public void search()
{
  //Vehicle is an enum whose value is selected by radi button
  if(this.vehicle.isCar())
  {
    carRequest.search();
  }
  else if(this.vehicle.isPushBike())
  {
    pushBikeRequest.search();
  }
  //boat checks and calls here ...

}

如果此搜索中的语句设计良好,则我不希望这样做.
我不确定,但是从请求对象调用dao search听起来是反模式的.这真的是个好方法吗?
我似乎正在创建6个类(3个请求对象和3个DAO),这听起来也不正确.由于每个搜索实现都不同,因此似乎无法摆脱泛型.

I hate this if statements in this search a good design should not need this check.
I am not sure but calling dao search from request object sound anti-pattern.Is this a good approach at all?
I seem to be creating 6 classes (3 Request Objects and 3 DAO)which again does not sound right.Can not seem to get away with generics since each search implementation is different.

有人可以给我更好的方法或任何相关建议吗?

Can someone please give me a better approach or any relevant advice.

推荐答案

正在使用JSF2和EJB3开发应用程序,而我没有使用CDI.

am developing an application using JSF2 and EJB3 and I am not using CDI.

我的建议与CDI有关.您为什么决定不使用它?不使用CDI,您将失去JSF Web开发中JEE6提供的两个最基本的新服务:上下文和依赖注入.您可以只使用EJB 3.1,但最终不会获得最简单的解决方案.我将从CDI开始,然后,如果我需要其他需求(例如事务,jmx,池等),那么EJB就会为您提供帮助

My advice is related to CDI. Why have you decided not to use it? No using CDI you are lossing two most fundamental new services provided by JEE6 in JSF web development : Contexts and Dependency injection. You could work exclusively with EJB 3.1, but you will not end up with the simplest possible solution. I would begin with CDI then if I need other requirements like transactions, jmx, pooling, etc.. then EJB comes to rescue you

这篇关于如何改善这种设计,该设计从基于JSF的前端调用第三方方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆