aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Purchase Request and layers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Purchase Request and layers" Watch "Purchase Request and layers" New topic
Author

Purchase Request and layers

Tadili Saad
Greenhorn

Joined: Sep 17, 2008
Posts: 20
Hi,

I'm designing a module of an application, and I wonder where I need to put some of the logic of this module.

The module consist of creating a purchase request consisting of items, suppliers and quantities.

I'm using struts2 with hibernate, I have three layer (presentation, business, integration).

I wonder what is best :

In the presentation layer
- Get an empty purchase request from the business layer and store it in the http session.
- add line items in the purchase request stored in the session.
- When the user is finished call the method endPurchaseRequest() from the business layer and store the purchase request in the database.


Or
In the presentation layer:

- Get an empty purchase request from the business layer (do not store it in the http session).
- each time an item quantity and supplier is added to the purchase request call a method addLineItem() from the business layer which adds the line item (the method returns the newly updated purchase request)
- When the user is finished call the method endPurchaseRequest() from the business layer and store the purchase request in the database.


Thanks
Joe carco
Ranch Hand

Joined: Apr 14, 2009
Posts: 82
Both seem fine to me. For the second one you would probably use a SFSB, but how are you going to keep reference to the SFSB for the duration of your Session? you would have to keep it somewhere, like your HttpSession. So you might aswell store all your temporary information in your HttpSession ie. use the first option.
Tadili Saad
Greenhorn

Joined: Sep 17, 2008
Posts: 20
Joachim Heidenreich wrote:Both seem fine to me. For the second one you would probably use a SFSB, but how are you going to keep reference to the SFSB for the duration of your Session? you would have to keep it somewhere, like your HttpSession. So you might aswell store all your temporary information in your HttpSession ie. use the first option.


Hi,


By SSFB, you mean an EJB Statefull Session Bean, because I'm not using EJBs in my business Layer, I'm just using POJO's.

For the second method :
How I see it is that the business layer expose a method with the following signature



the presentation layer calls this method each time the user add an item, the method return the newly update PurchaseRequest and the presentation layer put the PurchaseRequest in the request scope.
Also There's no call from this method (addItem) to the integration layer, just some validation stuff and adding the (Item, Supplier, Quantity) combo.
Joe carco
Ranch Hand

Joined: Apr 14, 2009
Posts: 82
So in the 2. option, if youre not going to use SFSB, you're going to put the updated PurchaseRequest object into the request scope every time? I find that rather cumbersome because you will have to store the Purchase request in some hidden fields or request parameters in your JSPs in every call otherwise your data will be lost. Why not store them in a HttpSession? You wont even need to have the method addItem return an updated PurchaseRequest becuase you would be using "call by reference."
Plus, every time your jsp (I'm assuming you're using JSPs in your presentation layer) sends PurchaseRequest member fields to its Servlet, the Servlet needs to reassemble the PruchaseRequest object, becuase a POST or GET request cannot pass objects, only String-type data.
Tadili Saad
Greenhorn

Joined: Sep 17, 2008
Posts: 20
Joachim Heidenreich wrote:So in the 2. option, if youre not going to use SFSB, you're going to put the updated PurchaseRequest object into the request scope every time? I find that rather cumbersome because you will have to store the Purchase request in some hidden fields or request parameters in your JSPs in every call otherwise your data will be lost.


Yes,

Also I'm using struts2 so it's all done behind the scenes.

Why not store them in a HttpSession? You wont even need to have the method addItem return an updated PurchaseRequest becuase you would be using "call by reference."


This project is an academic project, I want to be able to use the persistent state pattern (an implementation of the state pattern). for that I need to have all the methods that changes the state of the PurchaseRequest in an object in the business layer.
Also I need to make some validation on the quantity of the item added (like it cannot exceed a certain quantity). I guess this is a business matter so this validation cannot be done in the presentation layer (or am I wrong).


Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Purchase Request and layers