What is the best way to make a modular Java application

I am building a small website in Java (Spring MVC with JSP views), and I am trying to find the best solution for creating several reusable modules including (for example, "latest news", "upcoming events" ...).

So the question is: portlets, tiles, or some other technology?

+6
java spring-mvc module
source share
7 answers

If you are using Spring MVC, I would recommend using Portlets. In Spring, portlets are simply lightweight controllers because they are only responsible for a fragment of the entire page and are very easy to write. If you use Spring 2.5, then you can take full advantage of the new annotation support and fit nicely into your entire Spring application with dependency injection and other benefits of using Spring.

The portlet controller is almost the same as the servlet controller, here is a simple example:

@RequestMapping("VIEW") @Controller public class NewsPortlet { private NewsService newsService; @Autowired public NewsPortlet(NewsService newsService) { this.newsService = newsService; } @RequestMapping(method = RequestMethod.GET) public String view(Model model) { model.addAttribute(newsService.getLatests(10)); return "news"; } } 

Here NewsService will be automatically entered into the controller. The view method adds a List object to the model, which will be available as $ {newsList} in the JSP. Spring will look for a view called news.jsp based on the return value of the method. RequestMapping tells Spring that this controller is for VIEW portlet mode.

The XML configuration should only indicate where the view and controllers are:

 <!-- look for controllers and services here --> <context:component-scan base-package="com.example.news"/> <!-- look for views here --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/news/"/> <property name="suffix" value=".jsp"/> </bean> 

If you just want to embed portlets into an existing application, you can bundle a portlet container like eXo , Sun , or Apache . If you want to create your application as a set of portlets, you may need to consider a full-blown portal solution, such as Liferay Portal .

+4
source share

Tiles can be pain. A huge improvement over what it was before (i.e. Nothing), but rather a limitation.

Wicket may be more than what you are looking for, unless you are staying on JSP.

+2
source share

I do not recommend using portlets if your application is truly a web portal .

If you just want the “reusable components” to use JSP tagfiles , they are simple but extremely powerful because they are the same as regular JSPs.

I had experience using tiles, and the complexity is simply not worth it.

+2
source share

I am a big fan of GWT . It allows you to write your components like regular Java classes, and then you can embed them on your pages as you wish. It all ends with compilation in Javascript.

Here is an example:

 public class MyApplication implements EntryPoint, HistoryListener { static final String INIT_STATE = "status"; /** * This is the entry point method. Instantiates the home page. */ public void onModuleLoad () { RootPanel.get ().setStyleName ("root"); initHistorySupport (); } private void initHistorySupport () { History.addHistoryListener (this); // check to see if there are any tokens passed at startup via the browser's URI String token = History.getToken (); if (token.length () == 0) { onHistoryChanged (INIT_STATE); } else { onHistoryChanged (token); } } /** * Fired when the user clicks the browser 'back' or 'forward' buttons. * * @param historyToken the token representing the current history state */ public void onHistoryChanged (String historyToken) { RootPanel.get ().clear (); Page page; if (Page1.TOKEN.equalsIgnoreCase (historyToken)) { page = new Page1 (); } else if (Page2.TOKEN.equalsIgnoreCase (historyToken)) { page = new Page2 (); } else if (Page3.TOKEN.equalsIgnoreCase (historyToken)) { page = new Page3 (); } RootPanel.get ().add (page); } } 
+1
source share

I had a lot of experience working with portlets in combination with Ajax JSF (IceFaces) and Liferay Portal, and I would not recommend them to anyone - everything looks good when you read the tutorial and the real hell in practice. Of course, I think they are much more convenient and lightweight using Spring MVC and JSP, but in any case, the portlets do not support imho technology.

+1
source share

Tapestry is a Java web application platform with a focus on the easy creation of reusable components.

I used sitemesh and it is good for packing a set of pages into standard headers and footers, but Tapestry is better for creating components that are used on many pages, possibly many times on a page. Tapestry components can accept other components as parameters, allowing you to wrap the Sitemesh style.

0
source share

I'm not 100% sure what “reusable components” means in this context, but if you want certain common elements to appear on every page, such as a banner, footer, navigation links, etc. then look no more SiteMesh My team has successfully used it on several internationalized web applications.

0
source share

All Articles