views:

543

answers:

9

Hello,

I'm teaching Java EE at the university, and this was a question a student asked. I said "no", but I wasn't really sure, so I thought I might ask you mighty developers. :)

Basically, what I'd like to do is to use entities if they were in my context: cat getters, setters, etc, so like normal POJOs. if I use an EJB using its remote inferface, the entities gets decoupled from the core infrastructure, so that's a no-go.

I thought about writing a layer such as this in my MSc thesis. If it's a dead idea, feel free to tell me. If it's not, tell me if you'd like one.

Or if there is such a tool out there, let me know!

Thanks,

Zoltan

A: 

One alternative is the Spring Framework. Spring provides its own support for binding entity objects to the view and handles the getting/setting for you once it is wired up. There are many Spring modules to pick and choose from. Spring MVC and Spring Webflow are both worth checking out. Spring MVC (IMO) is simpler to get started with, but Sring Webflow allows for more complex navigation and more scope options (ex: flow scope). If you're looking for a book Spring In Action is descent. There are some concepts you will need to tackle (such as dependency injection) in order to use Spring but it is well worth the time.

rich
A: 

Another alternative is Tapestry5 framework. Tapestry is an open-source framework for creating dynamic, robust, highly scalable web applications in Java. Tapestry complements and builds upon the standard Java Servlet API, and so it works in any servlet container or application server.

Tapestry divides a web application into a set of pages, each constructed from components. This provides a consistent structure, allowing the Tapestry framework to assume responsibility for key concerns such as URL construction and dispatch, persistent state storage on the client or on the server, user input validation, localization/internationalization, and exception reporting. Developing Tapestry applications involves creating HTML templates using plain HTML, and combining the templates with small amounts of Java code. In Tapestry, you create your application in terms of objects, and the methods and properties of those objects -- and specifically not in terms of URLs and query parameters. Tapestry brings true object oriented development to Java web applications.

iberck
A: 

The ideology behind beans is nowadays in any proper Java framework I know of. As rich mentioned, Spring is a good/great all-around business logic framework (check out its jdbc template classes, those are simply awesome - another great gem is applicationContext.xml which is ) and for view layer I personally prefer Apache Wicket.

I don't believe you should make your own but instead find a framework that suits your needs and start contributing to its code base, that way you get to start with an already formed user base and your code will get authored more thoroughly which in turn will make you a better programmer.

P Arrayah
A: 

I've never tried it, but JSF is supposed to work better with Facelets than with JSP.

IBM has an article about it.

R. Bemrose
A: 

Ah. It seems you didnt get my question right :)

Beans are there to provide services inside an application. Lets say I'd like to develop a standalone java application with a swing gui, and from that application I'd like to use the entities present at the java ee app's scope.

That is what I'd like to to seamlessly: create entities, modify them, delete them in an intuitive way, without caring about EntityManager-detachment problems (if you call an EJB remotely and it passes back an entity object, it will be detached before return).

I dont want to develop a web application. JSF/JSP and such is strongly integrated, but in many environments a standalone client application would be better. :)

A: 

grails (http://www.grails.org/) or griffon (http://griffon.codehaus.org/) may be of interest

Ray Tayek
A: 

StringTemplate is written by Terrence Parr, the guy behind ANTLR. If you're interested in generating some kind of textual presentation from a model, this is very good.

I have had excellent results using it to generate XML, web pages and dot files from the same model. You write a template to render an object. That template can call other templates (including recursively), based on the data derived from the model. (q.v. Picture Functions)

Getters and map.get() are callable directly from within the templates. The model can be any POJO. ST prides itself on its strict separation from the controller, so very little logic is allowed in the templates themselves.

As with all these little languages, it's something new to learn, and may not be what you're looking for. It was a really good fit for me.

jamesh
A: 

Seeing your comment in the middle, i see that you want a desktop framework over JEE.

The answer here is that JSF works over the servlet api. And is definitely for the web, but wait, you can still embed tomcat or jetty in your application!

The possibilities are pretty much endless, if your business layer is well defined, just build a swing layer that calls your business functions.

Also, JEE is an API, some parts can be replaced, or you can just use part of it. The container is mostly for dealing with EJB, Servlets JNDI and other small stuff. All this can be used by desktop apps also.

So the answer depends on your specific goal and the actual design/implementation of the application.

Loki
A: 

In a basic modern world JEE application, it is broken into various layers, where you have 4 basic layers

+--------------------+
|   Presentation     |
+--------------------+
| Controller/Actions |
+--------------------+
| Business Delegate  |
|     (Service)      |
+--------------------+
|  Data Access Layer |
+--------------------+
|      Database      |
+--------------------+

Your applications should be split into these layer right from the beginning, such that you can at any given point of time replace any layer without effecting any of it's sibling layer.

Example if you used JDBC for the Data Access layer, you should be able to replace it with Hibernate without affecting the business delegate or Database layer. The benefit of using such an architecture is to allow collaboration with multiple technologies. You business delegate (service layer) should be able to talk to a web service and handle the application processing without even going to a browser!

Regarding using JSP as the presentation layer, there are other technologies available like, velocity, freemarker, as iberck mentioned above, tapestry also has it's own rendering engine. You can use XML + XSLT also to render the UI. There are UI managing apps also available like Tiles and sitemesh, that help you integrate various techs as different components of the page and show them as one.

You can also use light weight swing components clubbed with JNLP and develop a desktop style enterprise application. All we need is a little imagination and client requirement and we can use literally anything as the presentation layer.

Varun Mehta