• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Alternative Implementations of MVC

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the springsource.org site I read:

If you do not want to use Spring's web MVC, but intend to leverage other solutions that Spring offers, you can integrate the web MVC framework of your choice with Spring easily. Simply start up a Spring root application context through its ContextLoaderListener, and access it through its ServletContext attribute (or Spring's respective helper method) from within a Struts or WebWork action. No "plug-ins" are involved, so no dedicated integration is necessary. From the web layer's point of view, you simply use Spring as a library, with the root application context instance as the entry point.


So it tells about using Spring as a library. I am confused because calling from Struts (I assume same as from WebWork) action implies that we are already using Struts for MVC, not an alternative. An example I would like to see (if it is possible at all): you hit an URL and (as in all samples) get the first page but already rendered by some alternative MVC implementation say of your own.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What they are saying is for the web tier, you can use Spring MVC, Struts, Tapestry, JBoss Seam, Servlets, etc and still use the Spring Framework for the middle tier. Spring MVC != Spring Framework. Spring MVC is a module to the Spring Framework for the web tier.

So in Struts I can have an Action class extend Spring's ActionSupport class which gives it a getApplicationContext method so that I could in an Action call getBean("orderService")

Mark
 
Alex Prohorov
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mark!

What I am asking for is if it is possible tho use proprietary presentation layer without even mentioning (not to tell - using) existing things - Struts, Velocity etc. Not even JSP. Ideally there would be an API for that.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alex Prohorov wrote:Thank you Mark!

What I am asking for is if it is possible tho use proprietary presentation layer without even mentioning (not to tell - using) existing things - Struts, Velocity etc. Not even JSP. Ideally there would be an API for that.



I still don't understand.

I can use any presentation layer I want, even internally created ones. But internally ones will have to write their own basic integration to Spring Framework. When you say not even JSP, I can point to the Play Framework as an example of a presentation layer that isn't Servlet/JSP spec for web that has Spring integration. There is also Swing, or public static void main() as "client layers" to access Spring ApplicationContext. It runs anywhere in any environment. Because it is a POJO.

Hope that helps

Mark
 
Alex Prohorov
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark!

Actually you got that right. Spring integration of Play! or Swing is very close to the point of my interest. The problem is that I am not much familiar with those two and just a beginner in Spring. And my question is - any hints on how that integration may be done in general. The document I quoted ("Simply start up a Spring root application context through its ContextLoaderListener, and access it through its ServletContext attribute (or Spring's respective helper method) from within a Struts") sounds a bit fuzzy on that. There should be a way NOT using Struts.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alex Prohorov wrote:Mark!

Actually you got that right. Spring integration of Play! or Swing is very close to the point of my interest. The problem is that I am not much familiar with those two and just a beginner in Spring. And my question is - any hints on how that integration may be done in general. The document I quoted ("Simply start up a Spring root application context through its ContextLoaderListener, and access it through its ServletContext attribute (or Spring's respective helper method) from within a Struts") sounds a bit fuzzy on that. There should be a way NOT using Struts.



Yes, so first to explain the ContextLoaderListener. And to say it works as long as you are using any Web Framework in existence that is built on top the JSP/Servlet spec with a web.xml file. So the ContextLoaderListener is a ServletListener that gets called back when a .war file is first being deployed in a Web Container. As soon as the ServletContext is created, the listener gets called and it creates an XmlWebApplicationContext. It then puts this into the ServletContext, which is available application wide. So any component in the Web Tier, Struts Actions, Servlets, Spring MVC Controllers, etc can all have access to the ServletContext which gives them access to the ApplicationContext.

If you are not in a JSP/Servlet container, then you have to find some other means to Bootstrap and create that ApplicationContext. So based on the environment that it is in, find some bootstrap way to run. Since Play just has a public static void main method as the start of the web app, you would put the code in there to create an ApplicationContext.

Hope that helps clear it up for you.

Mark
 
Alex Prohorov
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Mark, all that is helpful. Actually what I am thinking about is adding one more presentation layer implementation to Spring specifically HybridJava which has some good features that are currently not present in Spring MVC but obviously lacks all the rest (out of MVC) facilities of Spring. It may be the case that I really do not need ServletContext cause HybridJava (as a presentation layer) does well without it but obviosly ApplicationContext has to be somehow created for the business and so on layers.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would assume HybridJava is deployed in a Servlet environment too. So in that code just use WebApplicationContextUtils.getWebApplicationContext(servletContext)

Mark
 
Alex Prohorov
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:I would assume HybridJava is deployed in a Servlet environment too.

Absolutely yes (but not in a JSP environment). But it has its own mechanisms of binding data within presentation layer (extremely straightforward, simple and fast) so I do not see what for may I need ApplicationContext in presentation layer if I reuse HybridJava and thus maybe there is no need to push ApplicationContext into ServletContext - its usage may be limited to Business Layer and below.

I am thinking about transforming the presentation part generated by HybridJava compiler into a library that may be taken as a whole and just inserted into the Spring environment. Maybe (to begin with) I will be lucky in taking the simple non-WEB application example from a book (like HelloWorldSpringDI from Pro.Spring.3.pdf) and hooking up the Sample application of HybridJava to it. Interface is not very clear yet.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alex Prohorov wrote:

Mark Spritzler wrote:I would assume HybridJava is deployed in a Servlet environment too.

Absolutely yes (but not in a JSP environment). But it has its own mechanisms of binding data within presentation layer (extremely straightforward, simple and fast) so I do not see what for may I need ApplicationContext in presentation layer if I reuse HybridJava and thus maybe there is no need to push ApplicationContext into ServletContext - its usage may be limited to Business Layer and below.

I am thinking about transforming the presentation part generated by HybridJava compiler into a library that may be taken as a whole and just inserted into the Spring environment. Maybe (to begin with) I will be lucky in taking the simple non-WEB application example from a book (like HelloWorldSpringDI from Pro.Spring.3.pdf) and hooking up the Sample application of HybridJava to it. Interface is not very clear yet.



The ApplicationContext in the ServletContext IS ONLY the Business Layer and below components. For Spring MVC there is a separate ApplicationContext deployed and contained in the DispatcherServlet, so within the Front Controller Servlet there is a second ApplicationContext for the web tier components. So everything I said before is still what I was saying, and still applies. If I use a different view layer than Spring MVC, makes absolutely no difference when it comes to loading the ContextLoaderListener to create a middle tier business layer ApplicationContext to be exposed to the web tier components in any web framework.

" Absolutely yes (but not in a JSP environment)."

In Servlet but not JSP enviroment, there is no such difference. The Servlet/JSP environment is the same, it is the JSP/Servlet spec. Not two separate things. Now what you meant is that HybridJava runs in the JSP/Servlet environment/spec, but just doesn't use any jsp pages/files.

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic