Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to make a modular java web application [closed]

I'm building small web site in Java (Spring MVC with JSP views) and am trying to find best solution for making and including few reusable modules (like "latest news" "upcoming events"...).

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

like image 896
moriarty Avatar asked Sep 16 '08 12:09

moriarty


People also ask

Which features of Java help in providing modularity?

Parallel development: Java developers can quickly develop modules parallel to each other. Once all the modules are developed, they can be combined through an interface to create a suite. Using parallel development can save time.

How modularity is achieved in Java?

Modularity is a general concept. In software, it applies to writing and implementing a program or computing system as a number of unique modules, rather than as a single, monolithic design. A standardized interface is then used to enable the modules to communicate.

What is modularity java9?

Java Module System is a major change in Java 9 version. Java added this feature to collect Java packages and code into a single unit called module. In earlier versions of Java, there was no concept of module to create modular Java applications, that why size of application increased and difficult to move around.

What is modular web application?

A modular application is an application composed of loosely coupled, functional units called modules, and these modules can be linked together to form a larger application.


2 Answers

If you are using Spring MVC, then I would recommend using Portlets. In Spring, portlets are just lightweight controllers since they are only responsible for a fragment of the whole page, and are very easy to write. If you are using Spring 2.5, then you can enjoy all the benefits of the new annotation support, and they fit nicely in the whole Spring application with dependency injection and the other benefits of using Spring.

A portlet controller is pretty much the same as a 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, a NewsService will be automatically injected 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 named news.jsp based on the return value of the method. The RequestMapping tells Spring that this contoller is for the VIEW mode of the portlet.

The XML configuration only needs to specify where the view and controllers are located:

<!-- 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 want to simply embed the portlets in your existing application, the you can bundle a portlet container, such as eXo, Sun, or Apache. If you want to build your application as a set of portlets, the you might want to consider a full blown portlal solution, such as Liferay Portal.

like image 195
pjesi Avatar answered Sep 19 '22 12:09

pjesi


Tiles can be a pain. Vast improvement over what came before (i.e. nothing), but rather limiting.

Wicket might be more what you're looking for, unless you've settled on JSP.

like image 33
sblundy Avatar answered Sep 21 '22 12:09

sblundy