I'm learning Spring Roo and my purpose is to add some logic in generation time. In other words, I want to add some logic not to just generated project but with commands, before generation.
For example, standard things, like authentification, adding or listing entities can be done by roo commands. Imagine, that I want to modify list items page as the following - show only such entries which have even ID field. Also, I know that it's possible to add page mapping to custom page. But is it possible to preset this custom view with command line? I mean setting form action to generated handlers, ajax quesries - making view with command not by programmers' hands.
My understanding of Roo sounds like
Roo allows you only to rapidly start standart web app's parts but any complex custom logic should be implemented by yourself, after generation.
Is my understanding correct?
Important note - I understand, that generating business logic is very bad idea. My purpose is generating custom components with Roo which is already available but my custom components more custom than currently provided authentification+CRUD. So, I'm not going to generate enterprise application I just want to generate more complex components for future using it in other complex applications.
I want to be able to do the following - remove AOP from generated app, make it simple Spring MVC app, insert pre-hardcoded requestHandlers, JSP pages with POST/GET/AJAX requests to pre-coded requests. I know, that I can write simple program which simply opens .java file and inserts my pre-coded request mappings/handlers but is there any approach to do it with Roo commands?
You can create your custom Spring MVC add-on which generates all you want, as you wish. Examples about it are the add-ons for GTK or Flex.
So the answer is: yes but, to archive this, you must build your own MVC add-on. Also, if you do it, you could share it to community ;-)
Good luck!
Related
I am looking for some framework in java which can directly create html forms from database tables for crud operations on DB?
Spring Roo builds entities, pages and controllers based on Spring MVC,JPA. It can detect changes in the database. It is interesting that leaves no dependencies at runtime so, elements can be modified as regular Spring MVC elements, or you can add your own controllers, views, etc.
It has its limitations, of course, but it can be useful.
Would this work for you? http://incubator.apache.org/isis/index.html
Telosys Tools (an Eclipse plugin) can generate a full Spring MVC web application
from an existing database.
See the tutorials : https://sites.google.com/site/telosystutorial/
( if necessary the templates are customizable )
Maybe Spring Roo can help you:
http://www.springsource.org/spring-roo
http://static.springsource.org/spring-roo/reference/html/base-dbre.html
I think this is a big missing type framework in java. Roo works quite well, but it generates many files for each entity and seems to hava problems when you want to edit/remove some of them (at least it happened when I was trying).
I would like something like django admin, it should generate the page dynamically for each entity, probably with a view class describing the view.
For customizing a view even further it should follow a convention like:
views/domain/Entity.jsp -> replaces the whole view for the entity
views/domain/Entity_fieldname.jsp -> used as template for the field
Same thing for controllers, in roo there are many class that do almost the same thing. Why not use a default controller, and if the user defines a controller related to a entity, he could override the methods.
Of course this is not detailed enough, but I think pure java can improve a lot in making simple CRUD screens easy.
At least, this is the open source side. Inside business there are frameworks for CRUD, sometimes similara to this I describe. The hard part is making this framework decoupled from the other tools.
NetBeans can generate JSF pages based on your entities to do basic CRUD operations.
How-To: Generating a JavaServer Faces 2.x CRUD Application from a Database
try this:
barahisolutions.com/code-generator.htm
Its a Swing based code generator to reverse engineer databases and generate HTML forms ,entities,daos.
I have created a java based tool called Enfacade, that will generate CRUD screens from your DB tables.
The screens are data grid based and they will allow multiple grids to give one-to-many functionality.
You can then deploy to any java web application server using the runtime engine.
I watched some videos, demos of Roo and I kind of liked it. However before starting using it, I'd like to ask few things more experienced programmers with Roo.
Roo uses lot of AOP. Is it okay to write custom Java code and let Roo generated files just "be alone"? Or does whole Roo structure require some AOP knowledge. In other words, if I want to customize Roo project (add non CRUD functions), do I need to mess with AOP?
I've seen console approach of generating entities. Can Roo convert my database that already runs into Roo code (generate entities for me)?
Sometimes I have big entities. I don't want to show certain columns to UI. Is this kind of customization easily achievable?
Getting current views - I'd like to do some exports of what user sees right now in UI (say to XML). Auto export would be great, but at least can I easily fetch current data in UI view? (say user is seeing 10% of data in DB table, I'd like to store them in XML)
My database often changes. How does Roo go by with changing entities? That's dynamically adding/removing certain columns ...
Importing data (or whole new databases). I need to drop&create database on-the-fly. So UI might change a bit (new columns) and data will change for sure. Will it work with simple "run script and refresh"?
Rollbacks. Undo any changes you did. Does it provide built-in support for such a thing?
Reporting or at least integrating with popular reporting tools.
So what do you think? Does Roo match these? Should I give it a try? Or am I better to start from scratch using say plain GWT, JSF, whatever?
OT: seeing this requirements, feel free to leave comment what kind of Java framework would you choose. I am now thinking of GWT (kind of know that), JSF or Spring Roo (no, I am not planning to write JavaScript UI myself) ;-)
Here are the answers per my knowledge of Roo:
1.Roo uses lot of AOP. Is it okay to write custom Java code and let Roo
generated files just "be alone"? Or
does whole Roo structure require some
AOP knowledge. In other words, if I
want to customize Roo project (add non
CRUD functions), do I need to mess
with AOP?
No, you don't need to mess with AOP. Most of the Roo generated files (like .aj etc.) can be "left alone" apart from the files where you will put some code.
2.I've seen console approach of generating entities. Can Roo convert
my database that already runs into Roo
code (generate entities for me)?
Yes, [check out the Roo reverse engineering steps][1].
3.Sometimes I have big entities. I don't want to show certain columns to
UI. Is this kind of customization
easily achievable?
Yes.
4.Getting current views - I'd like to do some exports of what user sees
right now in UI (say to XML). Auto
export would be great, but at least
can I easily fetch current data in UI
view? (say user is seeing 10% of data
in DB table, I'd like to store them in
XML)
Yes.
5.My database often changes. How does Roo go by with changing entities?
That's dynamically adding/removing
certain columns ...
Refer my answer to question 2.
6.Importing data (or whole new databases). I need to drop&create
database on-the-fly. So UI might
change a bit (new columns) and data
will change for sure. Will it work
with simple "run script and refresh"?
Yes
7.Rollbacks. Undo any changes you did. Does it provide built-in support for
such a thing?
No. There is no support for rollback. There is a feature request pending for the same. However, there are work arounds.
8.Reporting or at least integrating with popular reporting tools.
This wouldn't be any different than any of your normal Java application just because you use Roo.
So what do you think? Does Roo match
these? Should I give it a try? Or am I
better to start from scratch using say
plain GWT, JSF, whatever?
Hope the above answers clarify!
When asking this I answered myself: use a jsp.
But ok, what about a lightweight, easy to use framework?
It would be perfect if this framework had Eclipse plugin,
so that I could generate all code in one click and simply fill one method body (populate it with the data), then in one click
create a war file using a wizard
and deploy it on Tomcat.
Are there such frameworks?
p.s. I use spring, but I think there are ways to integrate it into every framework.
Take a look at Spring Roo.
If you only want to list a few DB records, I would just implement it dirty with a simple JSP with scriptlets. But you could also use the JSP SQL Tag library for that.
A simple one method body controller that needs that forwards to a view can most easily be writen with the Stripes framework that forwards to a JSP view (see wikipedia code example for how easy this can be done).
Generating nice tables in JSP can quickly be done by the popular Display Tag library.
If your not afraid to learn something new take a look at Grails
One of the big advantages of Grails is that its a full stack environment. Meaning that out of the box you get everything you need for your web app development
Test Servlet container (Tomcat)
Test database (hypersonic)
ORM (hibernate)
etc.....
Once installed just run
> grails create-app
Then you have a complete runnable application. (Auto bootstraps your project creation and config)
I am modifying existing java web application that was written long time ago, and it is written in the wrost possible way. It has business logic and sql statemens in JSP files.
Because of the certain constraint, I can not re-design the entire application. but I can implement better design in any new feature that I add.
can anybody suggest me any MVC framework that I could easily integrate in existing app. I need to have framework that is not depended on many external jar files and it does not cause any issues with existing application.
I am modifying existing java web
application that was written long time
ago, and it is written in the wrost
possible way. It has business logic
and sql statemens in JSP files.
Sounds like a good candidate for being thrown away to me.
Because of the certain constraint, I
can not re-design the entire
application. but I can implement
better design in any new feature that
I add.
The entire app needs to be re-designed, but you can't redesign the entire app. It's contradictory.
can anybody suggest me any MVC
framework that I could easily
integrate in existing app. I need to
have framework that is not depended on
many external jar files and it does
not cause any issues with existing
application.
You can't help but cause issues with the existing application, and there will be external JAR dependencies if you use a framework. I'd still recommend it, because a framework will give you a lift that will be worth the extra JARs. Your WAR file will be bigger - so what? Disk space is cheap.
Sounds to me like MVC is the least of your problems. You should be concentrating on the idea of a properly layered application first. If you had well-defined persistence and service tiers you might have a chance.
Think about the problem without worrying about the UI for now. Start with the persistence tier. Get a DAO and model objects going. Then move onto the service tier: transactions, units of work, and use cases implemented using the DAO and model objects. Unit test both layers thoroughly.
Once you have those you're free to concentrate on making the view tier work properly. It'll be easier letting the controllers interact with services. Your UI can be HTML, CSS and JavaScript or Flex. All the logic will be out of the view and into the back end where it belongs.
Don't be afraid of JAR dependencies. It could steer you away from something that will help you. I'd recommend Spring first and foremost. It'll help with all your layering issues. Its web MVC is as good as there is, too.
If you can't re-design the whole application and are concerned about the weight of the framework, then I suggest not adding a framework. You'll end up with a Frankenstein build where the application is inconsistent, and not a lot of benefit.
Instead, why not roll your own? When you add new features (or revise existing ones), you don't have to cram everything into a jsp. Create your own data access layer, and your own business object, and link those to each other and to the UI in your jsps appropriately.
I am in the middle of creating my own custom MVC web framework for a project. This project has very old code base where one JSP page directly submits a form to another JSP whereas the paths are also hardcoded. Now it is a big project and putting Struts or JSF will take considerable amount of time.
So my suggestion is to build a small custom MVC framework and convert many existing page flows into it and also encourage them to develop newer applications using this new MVC frameworks.
I would like to review this with all of you whether it makes sense or we should directly go to the standard MVC frameworks.
My idea
1. Create one front controller servlet which will have URL pattern like /*.sm
2. This servlet reads one config file and creates a map whose key is requestedURI and value is the class name of the command bean.
3. upon intercepting any action request it reads the parameter map (request.getParameterMap()). This servlet refers the already built map, understand whose command bean is to be invoked? Creates an instance of this command bean.
4. pass the parameter map to this command bean and calls execute method.
5. if any exception is found, front controller servlet forwards the request to one global error page
6. if everything is fine, it then forwards the request to the expected URI (by removong .sm and replace it with .jsp)
Do you think I am missing anything here? I know I can make it more fancy by providing error page per request page in the config file or so but those can be done later as well.
I think that you will end up reinventing the wheel rolling your own MVC framework. I know that it is tempting to make your own, since you won't have to get used to a new API but instead create your own and you can more easily adapt it to your specific usecases. But since it seems to be a very long lived application you will have to consider the fact, that your own framework (which may now be state of the art) will be legacy in a couple of years, too.
And that's where adapting one of the popular frameworks comes in handy. The creators of a new framework usually want others to move, too, so they will (or should) offer easy integration or migration options away from the frameworks they think they are doing better (Spring is a good example since it e.g. seamlessly integrates with existing Struts applications and you can gradually move your application without putting the old one into trash). Additionally most current frameworks are very versatile (which can sometimes be a problem since they need more time to get into it) and can be adapted to almost all usecases.
So I would recommend to review the existing solutions carefully (you can learn a lot from their design decisions and errors, too) and only start making your own if none of them matches your requirements.