You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Carl Smith <cc...@yahoo.com> on 2005/07/29 15:40:05 UTC

what is M (of MVC) in struts

Struts privide strong C (of MVC) components, tyical of which are ActionServlet, Actions  and RequestProcessors, but I am wondering which part is the M (of MVC).

Thanks.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: what is M (of MVC) in struts

Posted by Craig McClanahan <cr...@gmail.com>.
On 7/29/05, Joe Germuska <Jo...@germuska.com> wrote:

> Struts does not provide any part of the "M" (Model).

The more colloquial way to say this is that Struts is a BYOM (Bring
Your Own Model) framework :-).

Craig

PS:  ActionForm is part of the view ... the purpose is to maintain the
server side state of your client side user interface components. 
People also use it to provide access to other model data, which sorta
works, but that wasn't ever the design intent.  You're better off
sticking model beans into the appropriate scope and accessing them
directly for that purpose.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: what is M (of MVC) in struts

Posted by netsql <ne...@roomity.com>.
Joe Germuska wrote:

> 
> 
> Struts does not provide any part of the "M" (Model). 

oh yeah, that's right.

.V


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: what is M (of MVC) in struts

Posted by Joe Germuska <Jo...@Germuska.com>.
At 6:40 AM -0700 7/29/05, Carl Smith wrote:
>Struts privide strong C (of MVC) components, tyical of which are 
>ActionServlet, Actions  and RequestProcessors, but I am wondering 
>which part is the M (of MVC).

Struts does not provide any part of the "M" (Model).  I think this is 
what often leads new developers to put too much model-type code 
directly into Action classes.

The idea is that you somehow make your model available to Struts, 
most often through the Servlet Application Context, or perhaps 
through a JNDI service, and then actions look up your model classes 
and perform operations on them.

So, you can use Struts PlugIn class to trigger some initialization of 
the servlet context at startup time, although if you are using 
Servlet 2.3 or newer, there's not too much reason not to just use a 
ServletContextListener (unless you are using Struts "modules" feature 
and your initialization code needs to know which module it's part of.)

For the last 18 months or so, the Spring Framework has been my 
favorite tool for assembling model components and making them 
available in the application context.  Spring includes quite a bit of 
direct support for Struts which makes this pretty easy to do.

Of course, Spring itself is also not the "M" in "MVC" -- we just use 
it to instantiate and initialize the service providers of our model 
layer.

Hope this helps.

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"Narrow minds are weapons made for mass destruction"  -The Ex

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: what is M (of MVC) in struts

Posted by netsql <ne...@roomity.com>.
The form"Bean". ;-)

it maps to html form.
.V

Carl Smith wrote:
> Struts privide strong C (of MVC) components, tyical of which are ActionServlet, Actions  and RequestProcessors, but I am wondering which part is the M (of MVC).
> 
> Thanks.
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: what is M (of MVC) in struts

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
The Model is something, conceptually, outside of Struts.  Struts provides
nothing for dealing with the Model.

Imagine that you write some classes that know how to talk to your
database, know how to perform your business logic.  Further imagine that
these classes have a known set of methods (i.e., expose a known interface)
that can be called to form the application.

More specifically, imagine you have an application where you want to be
able to maintain a list of students and what classes they are taking in
school.  Without arguing about how best to actually architect this (i.e.,
let's forget about DTOs and DAOs and persistence layers and all that and
keep it simple), you might come up with something like this:

Class Student
-------------
Method: List listStudents()
 lists all students in the database
Method: void createStudent(String studentName, String ssn)
 Creates a user with a given SSN in the database
Method: Map getStudent(String studentName)
 Gets all the details for a given student from the database
Method: void addClass(String studentName, String className)
 Adds a class a given student is attending
Method: void deleteClass(String studentName, String className)
 Deletes a class a givent student is attending
Method: List listClasses(String studentName)
 Lists all the classes a given student is attending

>From this you can create a webapp that allows you to list students, pick
one, see their details including what classes they are taking, and add and
remove classes.  Again, we're ignoring how you really should architect
this, I'm just trying to get the basic point across.

Also note that this is completely independant of the fact that you are
writing a webapp.  You can just as easily write a Swing-based client that
uses this class, or any other presentation technology.

Now, you have a single class that exposes a known interface that for all
intents and purposes represents your model.

Now, from your Struts Actions, you call these methods and render the
results as appropriate.  The method parameters like studentName and
className would probably be coming in as request parameters, so you just
instantiate your Student class and call the appropriate method, then take
the result and pass it to the view for display.  Struts itself doesn't
deal with the model for you.  How you get at these classes is also up to
you... could be a JNDI lookup, could be just included with your app, etc. 
Struts leaves this to you entirely.

Hope that answers your question :)

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Fri, July 29, 2005 9:40 am, Carl Smith said:
>
> Struts privide strong C (of MVC) components, tyical of which are
> ActionServlet, Actions  and RequestProcessors, but I am wondering which
> part is the M (of MVC).
>
> Thanks.
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Form bean's attribute displays as Html

Posted by Raj Tilak <ra...@hotmail.com>.
try one of the attribute in the bean:write which is
filter="true"

>From: Carl Smith <cc...@yahoo.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: Struts Users Mailing List <us...@struts.apache.org>
>Subject: Form bean's attribute displays as Html
>Date: Mon, 1 Aug 2005 13:07:47 -0700 (PDT)
>
>
>I have an attribute in my ActionForm (called myForm) called text, this text 
>have a value of
>
><a href="http://www.yahoo.com">Click here to Yahoo.com</a>, now I want this 
>attribute to be displayed on web page as a hyper link. I used <bean:write 
>name="myForm" property="text"/>, which prints <a 
>href="http://www.yahoo.com">Click here to Yahoo.com</a> on the screen. I 
>understand I should't use <bean:write> tag since it prints all the value to 
>JSPWriter, the thing is which is the correct tag/way to display the value 
>of the frombean's attribute as a html to the user?
>
>Thanks in advance.
>
>
>---------------------------------
>  Start your day with Yahoo! - make it your home page



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: AW: Form bean's attribute displays as Html

Posted by Carl Smith <cc...@yahoo.com>.
Thank you Leon Rosenberg and Raj Tilak, this works perfect by turning filter="false".

Leon Rosenberg <st...@anotheria.net> wrote:
In this (and only this case) you can use bean:write with filter="false" 

This will work


> -----Ursprüngliche Nachricht-----
> Von: Carl Smith [mailto:ccsmith20002001@yahoo.com] 
> Gesendet: Montag, 1. August 2005 22:08
> An: Struts Users Mailing List
> Betreff: Form bean's attribute displays as Html
> 
> 
> I have an attribute in my ActionForm (called myForm) called 
> text, this text have a value of 
> 
> Click here to Yahoo.com, 
> now I want this attribute to be displayed on web page as a 
> hyper link. I used > property="text"/>, which prints > href="http://www.yahoo.com">Click here to Yahoo.com on 
> the screen. I understand I should't use tag 
> since it prints all the value to JSPWriter, the thing is 
> which is the correct tag/way to display the value of the 
> frombean's attribute as a html to the user?
> 
> Thanks in advance. 
> 
> 
> ---------------------------------
> Start your day with Yahoo! - make it your home page 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



		
---------------------------------
 Start your day with Yahoo! - make it your home page 

AW: Form bean's attribute displays as Html

Posted by Leon Rosenberg <st...@anotheria.net>.
In this (and only this case) you can use bean:write with filter="false" 

This will work
 

> -----Ursprüngliche Nachricht-----
> Von: Carl Smith [mailto:ccsmith20002001@yahoo.com] 
> Gesendet: Montag, 1. August 2005 22:08
> An: Struts Users Mailing List
> Betreff: Form bean's attribute displays as Html
> 
> 
> I have an attribute in my ActionForm (called myForm) called 
> text, this text have a value of 
> 
> <a href="http://www.yahoo.com">Click here to Yahoo.com</a>, 
> now I want this attribute to be displayed on web page as a 
> hyper link. I used <bean:write name="myForm" 
> property="text"/>, which prints <a 
> href="http://www.yahoo.com">Click here to Yahoo.com</a> on 
> the screen. I understand I should't use <bean:write> tag 
> since it prints all the value to JSPWriter, the thing is 
> which is the correct tag/way to display the value of the 
> frombean's attribute as a html to the user?
> 
> Thanks in advance. 
> 
> 		
> ---------------------------------
>  Start your day with Yahoo! - make it your home page 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Form bean's attribute displays as Html

Posted by Carl Smith <cc...@yahoo.com>.
I have an attribute in my ActionForm (called myForm) called text, this text have a value of 

<a href="http://www.yahoo.com">Click here to Yahoo.com</a>, now I want this attribute to be displayed on web page as a hyper link. I used <bean:write name="myForm" property="text"/>, which prints <a href="http://www.yahoo.com">Click here to Yahoo.com</a> on the screen. I understand I should't use <bean:write> tag since it prints all the value to JSPWriter, the thing is which is the correct tag/way to display the value of the frombean's attribute as a html to the user?

Thanks in advance. 

		
---------------------------------
 Start your day with Yahoo! - make it your home page