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

moriarty :

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?

pjesi :

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What's the best (or fastest) way to make this code shorter?

What's the best way to distribute Java applications?

What’s the best way to distribute a binary application for Linux?

what's the best way to use application constants in spring xml configuration?

What's the best approach in auditing a big java/j2ee web application

What's the best way to share business object instances between Java web apps using JBoss and Spring?

What's the best way to add a self-update feature to a Java Swing application?

What's the best way to persist data in a Java Desktop Application?

modular/pluggable java web application

What is the best way to profile a Java application in Eclipse?

What's the best way to model recurring events in a calendar application?

What's the best way to deliberately crash my Windows application?

What's the best way to make a Roslyn analyzer configurable?

What's the best way to make a new migration in a standalone Django app?

What is the best way to make a reusable tableview for different screens in the same application?

What is the best way to make synchronous calls using Angular's HttpClient?

what's the best way to generate an ember application?

Best practices configuring ehCache in modular java application

What's the best way to make a HTTP post with custom JSON BODY

What's the best way to make method run async?

What's the best way to make registration and login to android app with Firebase?

What's the best way to make a Count Down Timer?

What's the best way to make a parameter of a function mandatory?

What's the best way to make multiple draggable views programmatically?

What's the best way to make an std::string out of one char?

What's the best way to make EXISTS query in ArangoDB

What is the best way to make a (tab to window) system like web browsers?

What is the best way for creating Azure AD Api/Web Client Application

What's the best way to make a adaptive flutter app?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive