spring roo frontend twitter-bootstrap integration - spring-mvc

I want to develop a pretty standard webproject with all basic functionalities such as landingpage, user registration, login and so on.
Since I'm familiar with Java and Spring, I set up the a project with Spring Roo including DBRE from an MySql database, MVC and Spring security.
Right now I'm wondering how to go on with the UI. I would like integrate a template from twitter-bootstrap and I already downloaded a working example project (no apache tiles structure). I'm not very familiar with Apache tiles and frontend design in general so my question is, what would be the best way to integrate it and bypass the standard CRUD design?
Is it only necessary to design a new default-layout and reuse existing .jspx files? Also is it possible to take the existing bootstrap.jsp template which uses sitemesh from the bootstrap-example as a new template and reuse existing .jspx files?
Reuse is important since there are still entities which will change in future.
Appreciate any help!

I haven't personally used twitter-bootstrap, but I am fairly familiar with the Spring Roo structure.
My first bit of advice would be to just simply not use their UI stuff. Nothing says you have to generated your Controllers with scafolding, which takes the scafolded classes and auto-generates the CRUD methods and UI peices for you. In fact, in my last 4 projects, I did all the UI coding myself (I still used Tiles w/JSPs, and let Roo make all the relavent tiles configs and resource bundles). You can ALWAYS generate a plan Controller and use Roo for everything except the View pieces.
I don't see why you couldn't use the bootstrap.jsp you speak of. The Tiles implementation is done using the TilesViewResolver, I believe, which should be configured in the application_context.xml (or whatever Roo calls the context XML file). Just replace the TileViewResolver setup with something else. I would suggest reading up on Chapter 17.5 Resolving Views in the Spring Reference guide. I think for JSPs you want to use InternalResourceViewResolver.

Related

Modernizing Struts 1.x Application

I would like to modernize my Struts 1.x application. There are quite a number of articles which advocate migration of codes, instead of rewriting the entire system.
I would like to seek the advice of someone who has successfully modernize legacy applications.
My current system is using struts 1.x and JDBC prepared statements as the data access layer.
I am looking forward to improve the legacy application with the following objectives:
Web Pages should be coded with Responsive Web Design in mind.
Replace struts 1.x with Spring MVC
I am looking to breaking up the modernization into the following phases:
Phase 1 - Change all jsp pages to HTML 5 and CSS 3
Phase 2 - Change all DAO classes to Spring JDBC Template or Spring JPA
and transactions managed by Spring
Phase 3 - Ultimately, replace Struts 1.x Action Forms, Actions with Spring MVC
Before I start the changes, I would like to find out if it is possible for:
Struts 1.x with HTML 5 and CSS 3? I am looking at replacing all struts 1.x html taglibs with HTML 5 and JSTL/EL.
Running Struts 1.x with Spring 3/4? Is it possible to run non-spring managed pojo with Spring beans?
What should I take note of and how/what are the best practices to handle this modernization process? The code base is about 500k of HTML/JSP codes and 3 million Java codes.
It's been a while since I last worked with Struts 1.x, but I see no problem replacing at least most of the Struts tags with JSTL/EL. You should be able to paint HTML5 with Struts 1.x JSPs. I remember working using little or no Struts tags, only JSTL/EL, but this was before HTML5.
You can invoke Spring Context from any Struts ActionForm or, essentially any class within your webapp. You'll probably have to do it manually though and not with annotations, something like this:
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
With all this said, I can see you're intending to do a serious update of your app, therefore I must ask, are you positive about keeping Struts 1.x? If you want to ditch Struts tags, use Spring 3/4 and HTML 5, why not dispense with Struts entirely and migrate your app to Spring MVC? It's very easy to use, powerful and, needless to say, it integrates perfectly with the Spring components implementing your business logic, persistence, etc.
Cheers.
(Not an answer, informational.)
There's no reason you can't have an S1 app running alongside Spring MVC. It's a reasonable way to migrate piece-by-piece instead of a longer project that does a complete replacement.
Older Spring has direct support for Struts 1. Depending on your timeframe I might consider using the older Spring until you're further along.
Replacing S1 tags with pure HTML/CSS will be a pain because the S1 tags render other stuff besides just the input fields (e.g., labels, error messages, etc.) It's totally doable, especially if you write your own custom tags.
jQuery v. (AngularJS | React | similar) Switching to a full-on client-side app is a big lift, especially if your back-end isn't already designed that way. I wouldn't do that, but you could get a start on it by putting business logic in its own place and using that from the web layer. Then...
... you start to consume API calls on the client side using jQ or other client-side framework injected into the existing pages. Only then would I start considering going full SPA.
The bottom line is you have a fairly large app. Rather than converting the entire thing I would consider removing functionality from the mainline app and break it up into sub-applications, each of which could use whatever tech stack seems reasonable.
I've done a lot of project like this as a consultant: it's a lot of busywork that requires a wide range of knowledge and skills, and it's difficult to get right.

Design decision between backbone.js or Spring MVC

I have to develop an application which takes XML reports stored in File System parse it and put it into database and display the reports by querying the database in various MIME types(XML,JSON,RSS and HTML). So what I have done till now is parsed the XML reports in the file system ,setup schema for database in MongoDB,put data in database using Spring-data and also managed to have a web service which shows rough draft of reports in XML,JSON and RSS feed.Now I want to display the reports in HTML as well and my supervisor suggested me to use Backbone.js to dispaly it in HTML format by calling the web service.Kindly advice me to choose b/w Backbone.js or write another Spring MVC web service which generates reports in HTML.
Thanks in advance
Swaraj
What you are asking are two different things and choosing between them.
You have to know what your overall objective is with the webapp is and what framework is best for it.
Short answer, Spring MVC integrates with Dojo.js right out of the box, which might do what you need to do, but since your supervisor is suggesting otherwise your options are:
Use Spring MVC to construct and display the data in the HTML using what ever render of your choice.
Or
Build out your Spring MVC wepapp API so that you can use a JavaScript MVC framework, such as Backbone.js or one of the many others (see TODOMVC for samples), to interact with your spring controllers.
Option 1 might be easy enough, used in conjunction with JavaScript or jQuery and plugins
Option 2 would be good if your webapp is complex and will be mostly a SPA (single page app) that utilizes a lot of JavaScript and you want a way to organize your js code better. See JavaScript MVC diagram for an example of how it works.

What is (a relative) better strategy to load a resource file as a template in Spring 3.x mvc?

I am learning Spring 3.x MVC. I now have a regular web page setup with built in css in the html.
My first question - where should I store external css files and link them with the html files and still keep the L18n option available in the future? Should I keep the css in the WEB-INF/resources/css and make the resource directly available? But would it eliminate the L18n option?
My second question - to query a database, I have a query template XML file. I need to load the template into my model and modify a few keywords and send it through the database api. First thing that came to my mind is to put the keywords into something like ${keywords} in the template (like how the views are resolved), but I am not sure where to store the XML file (in the classpath? or in the web-inf?)? and how to set the variable in the template XML from my model?
Thanks,
Jason
It seem like you have two separate questions here.
In regards to CSS location, I'd recommend to try out Spring Roo tool. You can quickly generate a working web application with l18n support and number of other advanced features. This application could serve as a foundation for your own app or you can study its structure to learn many good practices for building Spring web applications.
In regards to your second question it is unclear what you want to substitute and at what time (i.e. deployment time or runtime) and also unclear what SQL templates you are using. I'd recommend to use iBatis/MyBatis framework, which has great integration with Spring and advanced templating support. There you can load your Spring contexts and template xmls from the Java application classpath.

Spring MVC (xml config nightmare?) vs spring roo?

I am just delving into the spring mvc (or spring roo), from what i have read it appears that spring MVC can be a nightmare to configure. I have to configure XML files, is this the web.xml file??? Or something different?
Is it still a nightmare or has it been improved?
Is there no editor for these XML files? I am using eclipse IDE
Spring roo apparently does spring mvc without XML config worries.
I would love anyone to explain the differences..
Thanks in advance
First Spring MVC is not a nightmare to configure, you just have to know what you are doing.
For that I would suggest you to download Spring IDE, which have a lot of XML editors that make you life easier if you are not experienced with Spring XMLs.
Basicly you have to configure 2 things
Web.xml ( this one is not because of spring it's Java EE, but you
need to include some spring MVC configs in it )
applicationContext.xml( this is where you define what you want from Spring )
servlet-context.xml ( this is also from spring MVC and have some servlet definitions as well as some routing ones)
one you get to know them you will find it easy to configure and very flexible.
One thing to notice Spring and Spring MVC are different things, I advise you to learn both of them.
Also Spring Roo is a code generator, for Cruds, simple things and setup projects it's great but if you need to build a reasonable big app that will need support it's always easier to create everything youself because it's easier to support when you know the code, so use it with care.
I'd add that Spring XML configuration can be as simple as a few lines, with the bulk of work done via annotations. It may not always be preferable to do it that way, but it's an option. Configuration can be divided between mechanisms when it makes sense to do so.
You might want to spend some time with the Spring documentation, at least regarding the components you're using. If you think configuring it is a nightmare, wait until you have to diagnose a problem brought about by magic based on convention without understanding how the underlying framework(s) work.

Django apps equivalent in ASP.NET MVC?

I currently develop with Django, but want to be ready when a future client inevitably requests a site done in ASP.NET MVC. While most of the structure and flow of ASP.NET MVC is more or less identical to Django and RoR, the one part I'm not sure about is the Apps methodology Django employs to make code reuse easier.
Is there an equivalent to Django apps in ASP.NET MVC? That is, can I create a feature, like tagging, comments, calendar of events, simple blog, etc. and bundle it up, making it portable to other projects with a minimum of glue code required to integrate it? Perhaps some kind of plugin or module system?
Django doesn't follow the traditional MVC pattern, since they advocate that in the Web world, their MTV is more suitable. In the overall, I prefer Django over Rails because of the django apps. You can do almost the same in RoR with the Rails vendor plugins, but it's not the same.
ASP.NET follows RoR structure, and therefor you don't have the reusable apps. If you check the folder structure in a MVC project, you don't even find the RoR's Plugin folder, so I bet you should do it VisualStudio-Like.
Create a reusable app, as a separated project, include references for that project in your main one, and in your Route file, just redirect to the other project's controllers.
This might be of interest as well: App Areas
we've tried to do something similar, albeit from a different angle. we use compositional controllers for increased reusability in bistro, and an ndjango as the templating language. what we start to see is controllers become more granular, and as a result less dependent on where they reside - more componentizable.

Resources