• 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

struts2 MVC pattern - business logic question

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I've been assign to a struts2 project and can't really understand the MVC pattern.
My question is mostly about the Action; should I think of any actions as the controller? Is this the place where I place all my business logic and the action's purpose is just to 'dispatch' the view? If so how do I do that?

In other words, what comes in the action (in first sight I thought -wow, all business logic should come here and life is easy [sa in the code below], but then I was reprimanded for doing so because I was told that this (action) is just the dispatcher).

So consider I need to do this:
1. user clicks a link and an action is started
2. I have a userID (based on the link)
3. I need to check a status of a registration
4a. if registration is APPROVED - create a pdf(A) and email to user+manager
4b. if registration is DENIED - create a pdf(B) and email to user+manager
4c. if registration is ON_HOLD - create pdf(C) and email user

can anyone provide a psude code for such action

thanks for any pointers, again - the question is not about the code, is more about the business logic --how should it be constructed and if the way presented above is ok (MVC in mind)

THANK YOU!
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put your business logic into helper classes and have them invoked by the Action. Yes, the Action should be part of the Controller in MVC and should not contain biz logic.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts Action classes are part of controller so they should not contain any business logic. A business delegate is used to delegate the business to business layer. In this manner we can separate the business logic from View and Controller.
More on MVC : http://java.sun.com/blueprints/patterns/MVC.html
 
Adrian Burlington
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd appritiate if anyone can give an example

Will this constitute a good MVC? is this how MVC expects me to separate the ACTION from BUSINESS LOGIC?


ACTION:



and the business side:


How would you do it better? (am I on the right track)
 
sudeep mahapatra
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A BusinessDelegate is to delegate/pass the information to business layer (For e.g. to a Bean) not to contain business logic itself.
Usually BusinessDelegate passes the info to a SF(SessionFacade) where the actual business logic resides.
For Example:

SampleAction [Action class]
/** Business Delegate instance */
private SampleBD sampleBD = new SampleBD();
execute() [this method should contain code to call testPDFCreate()]
testPDFCreate() [Here you call the createPDF() present in SampleBD]
{
sampleBD.createPDF();
}

SampleBD [It should contain a method that calls the business method present in Bean]
public createPDF()
{
// create Bean (EJBObject) of SampleSFRemote
// call createPDF()
// catch RemoteException
}
SampleSFRemoteHome [This is the Home Interface having the create method to create an EJB object]
SampleSFRemote create() throws CreateException, RemoteException;
SampleSFRemote [This is a session bean containing the abstarct method createPDF()]
createPDF() throws RemoteException ;
SampleSFBean
public createPDF() {}[Give the method body here. The actual business logic.]

One Important thing to check how you are passing information. Normaly ValueObject is used.
These objects are Serializable.
Can you please check in your project code. I think there must be some DesignPattern being followed.
Just see how other business flow is working.
 
reply
    Bookmark Topic Watch Topic
  • New Topic