Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts newbie

 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
im quite new to struts so i hope i can get some answers from the gurus.
is it common to put the business logic inside the action classes (as in many examples) or should the action just call the apropriate methods of the business logic ?
if the actions just call methods of the b-logic, then how do they get a reference to it ? whats a common way to do this (since the perform method and the constructor of the aciton is fixed) ?
well thats it for now....i hope somebody here can help me.
thanks a lot
karl
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by karl koch:
is it common to put the business logic inside the action classes (as in many examples) or should the action just call the apropriate methods of the business logic ?
if the actions just call methods of the b-logic, then how do they get a reference to it ? whats a common way to do this (since the perform method and the constructor of the aciton is fixed) ?

Hi Karl,
I'm fairly new to struts myself, but I'll let you know what I've learned from my research/coding thus far:
It depends on who you ask, but there seems to be a consensus that the Action classes are typically considered part of the Controller, not the Model, so it is best not to place business logic in the Actions.
From what I have seen, the recommended course of action is to code to an interface and use a pattern such as a Facade or a Factory to gain references to your business tier classes. This will effectively decouple your Model from your Controller, which is what you want with MVC2. The methods exposed by the interface to the business logic can(and often do) return Value Objects representing the state of the business tier, which your Views then display.
These are my impressions of what I have read and the strategy I employ in my code, somebody please feel free to correct me here if I am giving bad information!
E
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eric
thanks a lot for your reply.
i thought so too. separating the controller from the logic/model is a good idea.
do you have any good resources, a full struts example ? the examples if found (at least the ones with documentation) were small "hello world" like apps. there all the logic is inside the action.
thanks again.
karl
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found full Struts examples hard to come by, but About Struts is a great site, lots of info and tips, and an example application that I haven't gotten around to downloading yet.
The best references I've found yet have been recently published books like "Struts in Action" by Ted Husted(who also runs the About Struts site) and "Programming Jakarta Struts" by Chuck Cavaness. Both really good books.
HTH,
E
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic