Re: Struts + MVC Philosophical question
Yes, as a practical matter I would agree the two greatest advantages of a layered approach are error-handling and unit testing. In a JSP, by the time the code realizes there is an error, it's usually too late do much about it. Even more importantly, in a JSP, it can very hard to test the business logic using standard tools like jUnit. So problems are harder to detect and repair. By insulating the View from the Model, it becomes easy to runs demos, unit tests, and other simulations against the View by having the Controller provide whatever data is needed. I'm very much of the opinion that the View should just write what it is given without caring where it comes from. All the View needs to know is the context, the bean name, and the property name, and then it should just do like its told =:0) Of course, if the *bean* has a direct connection to the Model, then you *could be* tapping directly into the Model. But the point is that View has a contract with the Controller (and only the Controller) to expect a bean with a given protocol (in this context, under this name, with this property). If the Controller wants to pass it a bean that is connected to some Model, that's the Controller's business. If the Controller wants to pass it a bean that generates dummy data, that's up to the Controller too. If the Model changes its API, then the Controller has the option of using wrapper rather than changing its contract with the View. So that's up to the Controller too. So the thing to think about is not where the bean comes from, but who's *sending it* there and taking responsibility for the API contract. So long as there is a Struts action in there deciding what bean goes into what context, then the layers are being observed, and all is right with the universe. =:0) -T. Dan Cancro wrote: My favorite reason for insulating the view from the model is because otherwise, you could encounter errors in the middle of serving a page and the users would see a half-finished page. With insulation (via controller), you can make sure that all data retrieval by a page is foolproof. When you don't have web pages that start going to the browser before they are totally done being generated, you don't have to worry about this problem. -Original Message- From: Ted Husted [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 11, 2002 5:16 AM To: Struts Users Mailing List Subject: Re: Struts + MVC Philosophical question Struts really encourages a Layered Model 2/MVC architecture. Using a Layered arcitechture, it is incorrect for non-adjacent layers to develop direct dependencies. The View should talk to the Controller and the Controller should talk to the Model. The original M/V/C framework, Smalltalk, made good use of the Observer pattern to streamline processing. The View could register a listener with the Model and be apprised of any change. Though, that is not something many people would do today, since it violates the Layers pattern that evolved from MVC. If the whole shooting match evolved in today's environment, I believe the Observer pattern would have been applied differently, and the View would register with the Controller, which would then monitor the Model on the View's behalf. So, you're right, the original MVC pattern does not prevent the View from chatting with the Model and updating itself. The stricter Layers pattern that Web applications use on top of MVC does. But typing Layered/Model 2/MVC takes too long, and developers are lazy that way :o) So hereabout MVC does mean Smalltalk/Go4 MVC, it means Layered/Model 2/MVC. There's talk about christening that Web MVC or MVC2, but there's not a solid reference for that yet. Ade Barkah wrote: To nitpick... In a strictly philosophical terms, in MVC, the View *may* (and should!) directly access the Model, and on startup one *may* go straight to a View without passing through a Controller. Also, the Model *may* populate its own data without the help of a Controller. Of course when applying MVC to web applications, it's best if all user requests go through a control layer, but MVC per se does not mandate it. This practice is often referred to as the Front Controller pattern. For reference, see how MVC is applied in Smalltalk, Swing or even MFC. :) regards, -Ade -Original Message- From: Martin Cooper [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 9:41 PM To: 'Struts Users Mailing List' Subject: RE: Struts + MVC Philosophical question -Original Message- From: Struts Newsgroup [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 6:40 PM To: [EMAIL PROTECTED] Subject: Struts + MVC Philosophical question Subject: Struts + MVC Philosophical question From: André Augusto de Oliveira Aragão [EMAIL PROTECTED] === HI! I'm using
RE: Struts + MVC Philosophical question
To nitpick... In a strictly philosophical terms, in MVC, the View *may* (and should!) directly access the Model, and on startup one *may* go straight to a View without passing through a Controller. Also, the Model *may* populate its own data without the help of a Controller. Of course when applying MVC to web applications, it's best if all user requests go through a control layer, but MVC per se does not mandate it. This practice is often referred to as the Front Controller pattern. For reference, see how MVC is applied in Smalltalk, Swing or even MFC. :) regards, -Ade -Original Message- From: Martin Cooper [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 9:41 PM To: 'Struts Users Mailing List' Subject: RE: Struts + MVC Philosophical question -Original Message- From: Struts Newsgroup [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 6:40 PM To: [EMAIL PROTECTED] Subject: Struts + MVC Philosophical question Subject: Struts + MVC Philosophical question From: André Augusto de Oliveira Aragão [EMAIL PROTECTED] === HI! I'm using struts to develop an application. I have an action, that has an input page, and a result page. However, the input page needs information that is in the model. Following mvc, I can´t access the model directly from view. With struts, the input page is called before calling the action. Strictly following MVC, how can I populate the input page with model info I need? Any ideas? Following MVC, you should not be bypassing the controller and going straight to the view. ;-) The answer is to go through an action to get to the input page. The action can then set up any beans the input page will need, and then forward to it. -- Martin Cooper -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Struts + MVC Philosophical question
Strictly following MVC, how can I populate the input page with model info I need? Any ideas? You might want to take a look at creating a global forward that forwards to an Action. Create a global forward to an Action that does the stuff you need and then forward to the input page. Take a look at the O'Reilly Struts book on the theserverside.com. Chapter 4, page 15 under the heading of Using a Struts Action in the welcome-file-list. The explanation is better than I could give. Hope this helps. Alex __ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Struts + MVC Philosophical question
My favorite reason for insulating the view from the model is because otherwise, you could encounter errors in the middle of serving a page and the users would see a half-finished page. With insulation (via controller), you can make sure that all data retrieval by a page is foolproof. When you don't have web pages that start going to the browser before they are totally done being generated, you don't have to worry about this problem. -Original Message- From: Ted Husted [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 11, 2002 5:16 AM To: Struts Users Mailing List Subject: Re: Struts + MVC Philosophical question Struts really encourages a Layered Model 2/MVC architecture. Using a Layered arcitechture, it is incorrect for non-adjacent layers to develop direct dependencies. The View should talk to the Controller and the Controller should talk to the Model. The original M/V/C framework, Smalltalk, made good use of the Observer pattern to streamline processing. The View could register a listener with the Model and be apprised of any change. Though, that is not something many people would do today, since it violates the Layers pattern that evolved from MVC. If the whole shooting match evolved in today's environment, I believe the Observer pattern would have been applied differently, and the View would register with the Controller, which would then monitor the Model on the View's behalf. So, you're right, the original MVC pattern does not prevent the View from chatting with the Model and updating itself. The stricter Layers pattern that Web applications use on top of MVC does. But typing Layered/Model 2/MVC takes too long, and developers are lazy that way :o) So hereabout MVC does mean Smalltalk/Go4 MVC, it means Layered/Model 2/MVC. There's talk about christening that Web MVC or MVC2, but there's not a solid reference for that yet. Ade Barkah wrote: To nitpick... In a strictly philosophical terms, in MVC, the View *may* (and should!) directly access the Model, and on startup one *may* go straight to a View without passing through a Controller. Also, the Model *may* populate its own data without the help of a Controller. Of course when applying MVC to web applications, it's best if all user requests go through a control layer, but MVC per se does not mandate it. This practice is often referred to as the Front Controller pattern. For reference, see how MVC is applied in Smalltalk, Swing or even MFC. :) regards, -Ade -Original Message- From: Martin Cooper [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 9:41 PM To: 'Struts Users Mailing List' Subject: RE: Struts + MVC Philosophical question -Original Message- From: Struts Newsgroup [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 6:40 PM To: [EMAIL PROTECTED] Subject: Struts + MVC Philosophical question Subject: Struts + MVC Philosophical question From: André Augusto de Oliveira Aragão [EMAIL PROTECTED] === HI! I'm using struts to develop an application. I have an action, that has an input page, and a result page. However, the input page needs information that is in the model. Following mvc, I can´t access the model directly from view. With struts, the input page is called before calling the action. Strictly following MVC, how can I populate the input page with model info I need? Any ideas? Following MVC, you should not be bypassing the controller and going straight to the view. ;-) The answer is to go through an action to get to the input page. The action can then set up any beans the input page will need, and then forward to it. -- Martin Cooper -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- Ted Husted, Husted dot Com, Fairport NY US -- Java Web Development with Struts -- Tel: +1 585 737-3463 -- Web: http://husted.com/about/services -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Struts + MVC Philosophical question
Ummm, no. The Model can insulate (nay, even represent!) error conditions as well as (or even better than) the controller. :) Allowing the View to write to the Model is a (very) bad idea, but letting the View read from the Model is a good idea. regards, -Ade -Original Message- From: Dan Cancro [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 11, 2002 12:38 PM To: 'Struts Users Mailing List' Subject: RE: Struts + MVC Philosophical question My favorite reason for insulating the view from the model is because otherwise, you could encounter errors in the middle of serving a page and the users would see a half-finished page. With insulation (via controller), you can make sure that all data retrieval by a page is foolproof. When you don't have web pages that start going to the browser before they are totally done being generated, you don't have to worry about this problem. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Struts + MVC Philosophical question
-Original Message- From: Struts Newsgroup [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 6:40 PM To: [EMAIL PROTECTED] Subject: Struts + MVC Philosophical question Subject: Struts + MVC Philosophical question From: André Augusto de Oliveira Aragão [EMAIL PROTECTED] === HI! I'm using struts to develop an application. I have an action, that has an input page, and a result page. However, the input page needs information that is in the model. Following mvc, I can´t access the model directly from view. With struts, the input page is called before calling the action. Strictly following MVC, how can I populate the input page with model info I need? Any ideas? Following MVC, you should not be bypassing the controller and going straight to the view. ;-) The answer is to go through an action to get to the input page. The action can then set up any beans the input page will need, and then forward to it. -- Martin Cooper -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]