• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Purchase Request and layers

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic