Tuesday, February 15, 2011

Grails View as Spring MVC View

Introduction


The reference documentation of Spring 3 contains the following statements:

One of the areas in which Spring excels is in the separation of view technologies from the rest of the MVC framework. For example, deciding to use Velocity or XSLT in place of an existing JSP is primarily a matter of configuration. This chapter covers the major view technologies that work with Spring and touches briefly on how to add new ones.


The supported views are "JSP & JSTL", "Tiles", "Velocity & FreeMarker", "XSLT". Those are the major view technologies that work with Spring. The Spring MVC stack is usually : Spring MVC + JSP/JSTL + Tiles or SiteMesh. All these tools sound outdated, always usefull but outdated. On the other side there are frameworks like JSF, Grails, Play! (not exhaustive list) which come with great views more up to date.

Grails is the most logical choice because it uses Spring MVC internally. The task should be easier. To be honest this choice is not a very hard one because Grails view is elegant.

First step : web.xml


I basicaly replace the Grails dispatcher servlet with the Spring MVC dispatcher servlet. This dispatcher takes a configuration file, usualy named servlet-context.xml. There is no other specific configuration to do.

Second step : Configuring Grails



Grails has his own directories structure which is different of a standard Java Web Application. Resources resolver depend by default on this structure. Hopefully Grails supports WAR packaging so Grails can be configured to support a standard Java Web Application directories structure.

This configuration can be done through 2 files.

application.properties

This file is stored in the resources directory. It should contain :


The important line is grails.war.deployed.
Once set to true Grails resources resolver will use a WAR structure and Grails will cache GSP and not reload them. This parameter seems to be used for production mode only.


Config.groovy

This file is stored in the groovy directory. GSP reloading can be enabled with the following line :


Limitations

All the Grails taglibs cannot be used or should be used with caution. This is especially true for tags which use Grails controllers : g:form, g:link...
But creating a Grails taglib is quite easy.

Test sample

The Spring MVC controller


The Groovy server pages



This sample shows a Spring controller and a Groovy server pages. The GSP uses a UI composition pattern taglib I create (similar to facelet), a gsp template and a gsp layout.


Conclusion


The task is very easy. Nevertheless I lost quite some time on different things because of my poor Grails' knowledge. I created a custom view resolver and a custom context loader. All with some debugging to understand how Grails handles resources loading.

Nevertheless with these quite simple configurations you can use GSP as Spring MVC view. There are probably some other settings to do but for now this configuration seems to work perfectly.

The project is available on github.

In my opinion there is a big lack on the view side in the Spring MVC project. I'm really wondering what SpringSource is preparing.
Maybe a partnership or more ?.

99 comments:

  1. Nice article, but what do you mean by saying "these tools sound outdated, always usefull but outdated.", and then talking about JSF, which IS really outdated by means of approach of providing less control, complex unnecessary flow, overweight pages which are semantically wrong when HTML is produced and non-compatible implementations?

    Probably Grails is more fresh, I don't know, just starting trying, but I definitely can't name JSP/JSTL + sitemesh outdated, since they provide powerful control over end HTML, which is quite important for developers, crawlers and web-clients

    ReplyDelete
  2. Some of your statement about JSF are not true. Have a look at my benchmark, Primefaces is quite optimized and it renders a clean and a lightweight HTML. JSF flow has been improved with JSF 2 and you can used Spring Webflow or Seam.

    Yes, something can be usefull and provide powerful control over end HTML. It can on the other side outdated because newer tools provide more powerful control over end HTML and ease and improve the configuration and the developement.

    Grais view, Play! view (not exhaustive list) are in my opinion this newer tools.

    I encourage you to look at Grails.

    ReplyDelete
  3. MVC applied to WSGI or Java EE, is the Servlet a controller, dispatcher, or both? I think I've seen system diagrams where the controller and the dispatcher are different. Thanks for sharing your informative post.

    ReplyDelete
  4. Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post. It is really very helpful for us and I have gathered some important information from this blog.

    JAVA J2EE Training in Chennai

    ReplyDelete
  5. Is it possible to do that without Grails? I mean using GSP pages as views gluing Spring MVC framework? Thanks

    ReplyDelete
  6. I have learned much from your post. I would definitely bookmark your site to be updated with your upcoming articles. Great job! So much information...
    Regards,
    iOS Training in Chennai | Informatica Training in Chennai

    ReplyDelete
  7. The information you have given here are most worthy for me. I have implemented in my training program as well, thanks for sharing.

    Hadoop Training Chennai
    Hadoop Training in Chennai

    ReplyDelete
  8. I have read your blog, it was good to read & I am getting some useful info's through your blog keep sharing... Informatica is an ETL tools helps to transform your old business leads into new vision. Learn Informatica training in chennaifrom corporate professionals with very good experience in informatica tool.
    Regards,
    Best Informatica Training In Chennai|Informatica training center in Chennai

    ReplyDelete
  9. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
    Regards,
    ccna training in Chennai|ccna institutes in Chennai|ccna courses in Chennai

    ReplyDelete
  10. Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
    Regards,
    SAP training in chennai|SAP course in chennai|SAP Training in Chennai|sap course in Chennai

    ReplyDelete
  11. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog.
    Regards,

    Regards,
    CCNA Training in Chennai | CCNA Training Institute in Chennai | Best CCNA Training in Chennai

    ReplyDelete
  12. Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
    Devops interview Questions

    ReplyDelete
  13. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    hadoop training in chennai

    hadoop training in bangalore

    hadoop online training

    hadoop training in pune

    ReplyDelete
  14. can you offer guest writers to write content for you? I wouldn’t mind producing a post or elaborating on some the subjects you write concerning here. Again, awesome weblog!
    occupational health and safety course in chennai

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
    Azure Training in Chennai

    ReplyDelete
  17. I really enjoyed your blog Thanks for sharing such an informative post.
    Best- Web -Designing -services- in -Noida

    ReplyDelete
  18. Thanks for sharing the knowledge i have creating blog boardingschoolinda really appreciating work

    ReplyDelete
  19. nice blog
    get best placement at VSIPL

    digital marketing services
    web development company
    seo network point

    ReplyDelete
  20. ethical hacking online course is a way to learn ehtical hacking and become a professional hacker

    ReplyDelete
  21. Uttarakhand Govt jobs 2019, Uttarakhand Sarkari Naukri
    -------------------------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Uttarakhand-Govt-Jobs-2019.html
    ---------------------------------
    Google Careers - Currently more then 4000 job opening's in Google, Procedure of how to get a job in Google, Including topics - Google Careers, Google Cloud Careers, Google Careers Students, Google X Careers, Google Health Jobs and other related job's
    ------------------------------------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Google-Careers-How-to-get-a-job-in-Google.html


    JRF and Field Assistant Recruitment in Indian Institute of Soil and Water Conservation (IISWC), Dehradun, Indian Council of Agricultural Research (ICAR)
    ---------------------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/JRF-and-Field-Assistant-Recruitment-in-IISWC-Dehradun.html


    Employment News (Government of India) in English Date : 19 OCTOBER - 25 OCTOBER 2019 Download P.D.F
    रोजगार समाचार (भारत सरकार) हिंदी में दिनांक 19 OCTOBER - 25 OCTOBER 2019 डाउनलोड पी.डी.ऍफ़ (P.D.F)
    -------------------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Employment-News-and-Rojgar-Samachar-PDF-Download.html


    सहायक वन संरक्षक परीक्षा-2019 प्रवेश पत्र, सहायक वन संरक्षक परीक्षा-2019 के अन्तर्गत अभ्यर्थियों की अनर्ह सूची
    ----------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Admit-card-of-UKPSC-ACF-Exam-2019-.html


    Project Fellow and Project Assistant Recruitment inThe Wildlife Institute of India, Dehra Dun
    Essential Qualification (EQ) : Bachelors’ Degree in any discipline related to Biological Science/Life Science/Ecological Sciences from a recognized university
    -------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Project-Fellow-and-Project-Assistant-Recruitment-in-WII-Dehradun.html

    Google Cloud Jobs - Key Account Director / Executive, Google Cloud Job recruitment in Bangalore, Karnataka, India
    ----------------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Google-Cloud-Job-Key-Account-Executive-recruitment-in-Bangalore.html


    Advertisement of Section Officer and Assistant in WII Dehradun
    -----------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Section-Officer-and-Assistant-Recruitment-in-WII-Dehradun.html

    ReplyDelete
  22. http://uttrakhandcoldandcuttings.co.in/Uttarakhand-Govt-Jobs-2019.html

    ReplyDelete
  23. I devoured a couple of articles published on your blog and found them genuinely considerable. The way you keep imparting your valuable insights here is appreciated.
    Tuition Service Lucknow | Home Tuition Service

    ReplyDelete
  24. Uttarakhand Govt jobs 2019, Uttarakhand Sarkari Naukri
    -------------------------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Uttarakhand-Govt-Jobs-2019.html

    Uttarakhand Jobs and Uttarakhand Govt jobs 2019

    Google Cloud Jobs - Key Account Director / Executive, Google Cloud Job recruitment in Bangalore, Karnataka, India
    ----------------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Google-Cloud-Job-Key-Account-Executive-recruitment-in-Bangalore.html


    Advertisement of Section Officer and Assistant in WII Dehradun
    -----------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Section-Officer-and-Assistant-Recruitment-in-WII-Dehradun.html

    13 Junior Research Fellow and 2 Research Associate Vacant Project Posts in Defence Research and Development Organization (DRDO) Defence Institute of Bio Energy Research] (DIBER) Haldwani -263139, Nainital (Uttarakhand
    --------------------------------
    http://uttrakhandcoldandcuttings.co.in/13-JRF-and-2-RA-Vacant-Posts-in-DRDO-DIBER-Haldwani.html

    उत्तराखंड अधीनस्थ सेवा आयोग (UKSSSC) के तहत गोविंद वल्लभ पंत कृषि एवं प्रौद्योगिकी वश्वविद्यालय, पंतनगर में समुह 'ग' के अंतर्गत सहायक लेखाकर के 93 रिक्त पदों (80 पद सीधी भर्ती तथा 13 पद बैकलॉग पदों की विज्ञप्ति
    विज्ञापन प्रकाशन की तिथि : 25.10.2019
    ऑनलाइन आवेदन पत्र भरने की प्रारंभ तिथि : 31.10.2019
    ऑनलाइन आवेदन पत्र भरने की अंतिम तिथि : 15.12.2019
    परीक्षा शुल्क जमा करने की अंतिम तिथि : 17.12.2019
    लिखित परिक्षा की प्रस्तावित तिथि : जनवरी 2020
    परीक्षा शुल्क :
    अनारक्षित : ₹300/-
    आथिर्क रूप से कमजोर : ₹ 300/-
    उत्तराखण्ङ अनुसूचित जाति : ₹150/-
    उत्तराखण्ङ दिव्यांग ₹150/-
    आयु : 21 से 42 वर्ष
    शैक्षिक योग्यता : वाणिज्य स्नातक अथवा बचोलर इन बिजनेस (BBA) अथवा पोस्ट ग्रेजुएशन इन अकाउंटेंसी।
    2.हिंदी टंकण में 4000 की- डिप्रेशन गति।
    वेतनमान: 5200- 20200 ग्रेड वेतन - 2800
    http://uttrakhandcoldandcuttings.co.in/UKSSSC-Group-C-93-Vacant-Posts-of-Sahayak-Lakhakar-in-GBPUAT.html



    Senior and Junior Office Assistant Recruitment in (GBPNIHESD) G. B. Pant National Institute of Himalayan Environment and Sustainable Development Kosi-Katarmal, Almora 263643 (Uttarakhand)
    Age Limit: 40 Years
    Essential Qualification : Graduate in commerce
    -------------------------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Office-Assistant-Advertisement-in-GBPNIHESD-Almora.html


    Advertisement of Nursing Officer (Staff Nurse GradeII) on Direct Recruitment Basis in All India Institute of Medical Sciences, Rishikesh, 24920
    Last date of submission of Application Form is 24-12-2019
    -----------------------------------------
    http://uttrakhandcoldandcuttings.co.in/Advertisement-of-Nursing-Officer-in-AIIMS,-Rishikesh.html

    ReplyDelete
  25. Its a wonderful post and very helpful, thanks for all this information.
    Fashion Designing Institutes in Uttam Nagar

    ReplyDelete
  26. FOSTIIMA Business School is a pioneer in management studies in India and has figured consistently in the list of top B-Schools for students in India. FOSTIIMA Business School in Delhi are Well-Known for Providing Quality Management Education in the Fields Such as Accounting, Human Resource, Marketing, Finance, and Many Others Specialization. If you are more information visit a website : https://www.fostiima.org/


    best mba college
    best mba college in delhi
    best mba college in delhi ncr
    best mba college in india
    best mba colleges
    best mba colleges in delhi
    best mba colleges in delhi ncr
    best mba colleges in india
    best mba institute in delhi
    best mba institute in delhi ncr
    best mba institute in india
    best mba institutes
    best mba institutes in delhi
    best mba institutes in delhi ncr
    best mba institutes in india
    best mba program
    best mba program in india
    best mba programs
    best mba programs in india
    mba
    mba college
    mba college in delhi
    mba college in delhi ncr
    mba college in india
    mba colleges
    mba colleges in delhi
    mba colleges in delhi ncr
    mba colleges in india
    mba in delhi
    mba in delhi ncr
    mba institute
    mba institute in delhi
    mba institute in delhi ncr
    mba institute in india
    mba institutes
    mba institutes in delhi
    mba institutes in delhi ncr
    mba institutes in india
    mba program in delhi
    mba program in india
    mba programs
    mba programs in delhi
    mba programs in india
    top mba college
    top mba college in delhi
    top mba college in delhi ncr
    top mba college in india
    top mba colleges
    top mba colleges in delhi
    top mba colleges in delhi ncr
    top mba colleges in india
    top mba institute
    top mba institute in delhi
    top mba institute in india
    top mba institutes
    top mba institutes in delhi
    top mba institutes in india
    top mba program
    top mba programs
    top mba programs in india
    top 10 business schools in india
    top 10 mba college
    top 10 mba college in delhi
    top 10 mba college in india
    top 10 mba colleges in delhi ncr
    b school
    b school in delhi
    b school in delhi ncr
    b school in india
    b schools
    b schools in delhi
    b schools in delhi ncr
    b schools in india
    best b school
    best b school in delhi
    best b school in delhi ncr
    best b school in india
    best b schools
    best b schools in delhi
    best b schools in delhi ncr
    best b schools in india
    best business school
    best business school in delhi
    best business school in delhi ncr
    best business school in india
    best business schools
    best business schools in delhi
    best business schools in delhi ncr
    best business schools in india
    business school
    business school in delhi
    business school in delhi ncr
    business school in india
    business schools
    business schools in delhi
    business schools in delhi ncr
    business schools in india
    top b school
    top b school in delhi
    top b school in delhi ncr
    best management institute in delhi ncr
    best management institute
    best management institute in delhi
    top 10 mba colleges in india
    top 10 pgdm college in india
    top 10 pgdm colleges in delhi
    top 10 pgdm colleges in india
    best pgdm college
    best pgdm college in delhi
    best pgdm college in delhi ncr
    best pgdm college in india
    best pgdm colleges
    best pgdm colleges in delhi
    best pgdm colleges in delhi ncr
    best pgdm colleges in india
    best pgdm course in india
    best pgdm courses in india
    best pgdm institute in delhi
    best pgdm institute in delhi ncr
    best pgdm institute in india
    pgdm
    pgdm college
    pgdm college in delhi
    pgdm college in delhi ncr
    pgdm college in india
    pgdm colleges
    pgdm colleges in delhi
    pgdm colleges in delhi ncr
    pgdm colleges in india
    pgdm course
    pgdm course in delhi
    pgdm course in india
    pgdm courses
    pgdm courses in delhi
    pgdm courses in delhi ncr
    pgdm courses in india
    pgdm in delhi
    pgdm in delhi ncr
    pgdm in india
    pgdm institute
    pgdm institute in india
    pgdm institutes
    pgdm institutes in delhi
    pgdm institutes in delhi ncr
    pgdm institutes in india
    top pgdm college in delhi
    top pgdm college in india
    top pgdm colleges in delhi
    top pgdm colleges in india
    top pgdm institute in delhi
    top pgdm institutes in delhi

    ReplyDelete
  27. Awesome..You have certainly explained …Its very beneficial for me to recognise about new matters.
    .Keep on blogging.
    click here for more info.

    ReplyDelete
  28. Its really great being a content writer I can understand how tough is it to write and develop the content ,Thanks for sharing this wonderful information SAP Training in Lucknow, Digital marketing training in Lucknow, AUTOCAD Training in Lucknow, PYthon Training in Lucknow, SAP FICO Training in Lucknow .

    ReplyDelete
  29. Thanks for Sharing a very Nice Post & It’s really helpful for everyone. Keep on updating these kinds of
    Informative things Otherwise If anyone Want to Learn SAP Training Course Basic to Adv. Level So Contact THERE- 9599118710

    Some Best SAP Training Center in Delhi, India

    sap training institute in delhi
    sap training center in delhi
    sap training in delhi
    sap course in delhi

    ReplyDelete
  30. I was pretty pleased to find this site. I wanted to thank you for ones time for this particularly wonderful read!! I definitely loved every bit of it and i also have you saved as a favorite to check out click here new stuff in your blog.

    ReplyDelete

  31. This is most informative and also this post most user friendly and super navigation to all posts. Thank you so much for giving this information to me. SAP training in Chennai.
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  32. Take admission in S.N Memorial Public School is Top CBSE School in Dehradun city, Bhauwala which offers English medium, secular, co-educational education from classes Nursery to XII.
    The School is affiliated to the Central Board of Secondary Education (CBSE).

    CBSE school in Dehradun
    Top School in Dehradun
    Dehradun Famous School
    Best school in Dehradun fees
    Best Day Schools in Dehradun

    ReplyDelete
  33. Take admission in S.N Memorial Public School is Top CBSE School in Dehradun city, Bhauwala which offers English medium, secular, co-educational education from classes Nursery to XII.
    The School is affiliated to the Central Board of Secondary Education (CBSE).

    CBSE school in Dehradun
    Top School in Dehradun
    Dehradun Famous School
    Best school in Dehradun fees
    Best Day Schools in Dehradun

    ReplyDelete
  34. Thanks for sharing such a wonderful blog on Mean Stack .This blog contains so much data about Mean Stack ,like if anyone who is searching for the Mean Stack data,They will easily grab the knowledge of from this.Requested you to please keep sharing these type of useful content so that other can get benefit from your shared content.

    AWS training in Chennai<

    AWS Online Training in Chennai

    AWS training in Bangalore

    AWS training in Hyderabad

    AWS training in Coimbatore

    AWS training

    ReplyDelete
  35. Fire safety training is important because it gives your employees the valuable knowledge and skills they need to prevent fires and get out of burning buildings. So we are providing Safety Officer Course in Bihar and Lucknow with Safety Officer Jobs in lucknow and Bihar.
    https://nishe.in/safety-training/

    ReplyDelete
  36. This comment has been removed by the author.

    ReplyDelete
  37. your blog's design is simple and clean and i like it. Your blog posts about Online writing Help are superb. Please keep them coming. Greets!

    Big Data Training Institute in Pune
    Hadoop Training in Pune

    ReplyDelete
  38. I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog. Data Science

    ReplyDelete
  39. Ah,so beautiful and wonderful post!An opportunity to read a fantastic and imaginary blogs.It gives me lots of pleasure and interest.Thanks for sharing.
    Data Science Training In Chennai

    Data Science Course In Chennai

    ReplyDelete
  40. This comment has been removed by the author.

    ReplyDelete
  41. This comment has been removed by the author.

    ReplyDelete
  42. I want to say thanks to you. I have bookmark your site for future updates. ExcelR Data Science Course In Pune

    ReplyDelete
  43. This comment has been removed by the author.

    ReplyDelete
  44. It is amazing and wonderful to visit your site. Thanks for sharing information; this is useful to us....

    AI training course in Delhi

    ReplyDelete
  45. Thanks for the Valuable information.Really useful information. Thank you so much for sharing. It will help everyone.

    SASVBA is recognized as the best machine learning training in Delhi. Whether you are a project manager, college student, or IT student, Professionals are the best machine learning institute in Delhi, providing the best learning environment, experienced machine learning instructors, and flexible training programs for the entire module.

    FOR ORE INFO:

    ReplyDelete
  46. Informative and useful article with step by step explanation. Thanks for sharing Angular training in Chennai

    ReplyDelete
  47. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart

    Best Institute for Software Training Course in Delhi, India

    ReplyDelete
  48. Thank you so much for sharing these amazing tips. I must say you are an incredible writer, I love the way that you describe the things. Please keep sharing.

    Core to Advanced AutoCAD training institute in Delhi, NCR
    Advanced Excel Training, MIS & VBA Macros Training Institute

    ReplyDelete
  49. I believe there are many more pleasurable opportunities ahead for
    individuals that looked at your site.
    C#.NET Training In Chennai
    hadoop training in chennai
    software testing training in chennai

    ReplyDelete
  50. http://qwertyqueen.blogspot.com/2011/07/hiatus.html

    ReplyDelete
  51. Amazing! Very nice post. Grab the industrial robotics course in India from Brain n Bright institute.

    ReplyDelete
  52. Whatsapp Number Call us Now! 01537587949
    It Training In Dhaka
    USA pone web iphone repair USA
    USA SEX WEB careful
    bd sex video B tex
    bd sex video sex video
    bd sex video freelancing course

    ReplyDelete
  53. Needed to compose you a very little word to thank you yet again
    regarding the nice suggestions you’ve contributed here.

    ReplyDelete
  54. Incredible post I should say and a debt of gratitude is in order for the data. Schooling is certainly a tacky subject. Be that as it may, is still among the main subjects within recent memory. I appreciate your post and anticipate more. You have made some valid statements there. I looked on the web to study the issue and discovered a great many people will oblige your perspectives on this site...
    how to make the coolest paper airplane | how to make a good paper airplane that flies far | best paper model | the best glider paper airplane | paper airplane aerodynamics | super paper airplanes | how to make easy paper planes | control surfaces on a plane

    ReplyDelete
  55. I concentrate on a couple of reward stuff from it as well, gratitude for sharing your suggest. Microsoft Office 2010 crack is an effective software for all MS office and any version of MS Windows products. Microsoft Office 2010 Cracks

    ReplyDelete
  56. Great post. keep sharing such a worthy information.

    ReplyDelete
  57. Thank you for your wonderful post. Your post is really helpful and the information on this blog is very helpful for us and I have gathered some valuable information from it. Best Software Training Institute in Chennai.

    ReplyDelete
  58. Thank you for your post, and I look forward to reading more. There are some valid points you made there. While researching the issue, I discovered that a great many people would appreciate your viewpoints. https://www.besanttechnologies.com/.

    ReplyDelete