<p>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"...).</p>

<p>So the question is: Portlets, tiles or some other technology?</p>

[{'answer_id': 71737, 'author': 'sblundy', 'author_id': 4893, 'author_profile': 'https://Stackoverflow.com/users/4893', 'pm_score': 2, 'selected': False, 'text': '<p>Tiles can be a pain. Vast improvement over what came before (i.e. nothing), but rather limiting. </p>\n\n<p><a href="http://wicket.apache.org/" rel="nofollow noreferrer">Wicket</a> might be more what you\'re looking for, unless you\'ve settled on JSP.</p>\n'}, {'answer_id': 71743, 'author': 'tgdavies', 'author_id': 11002, 'author_profile': 'https://Stackoverflow.com/users/11002', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://tapestry.apache.org" rel="nofollow noreferrer">Tapestry</a> is a Java web app framework with an emphasis on easily creating reusable components.</p>\n\n<p>I have used sitemesh, and it is good for wrapping a set of pages in standard headers and footers, but Tapestry is better for creating components which are used on many pages, possibly many times per page. Tapestry components can take other components as parameters, which allows the Sitemesh style wrapping.</p>\n'}, {'answer_id': 71807, 'author': 'jodonnell', 'author_id': 4223, 'author_profile': 'https://Stackoverflow.com/users/4223', 'pm_score': 1, 'selected': False, 'text': '<p>I\'m a big fan of <a href="http://code.google.com/webtoolkit/" rel="nofollow noreferrer">GWT</a>.  It lets you write your components as normal Java classes and then you can insert them into your pages at will.  The whole thing ends up being compiled to Javascript.</p>\n\n<p>Here\'s an example:</p>\n\n<pre><code>public class MyApplication implements EntryPoint, HistoryListener\n{\n    static final String INIT_STATE = "status";\n\n    /**\n     * This is the entry point method.  Instantiates the home page.\n     */\n    public void onModuleLoad ()\n    {\n        RootPanel.get ().setStyleName ("root");\n        initHistorySupport ();\n    }\n\n    private void initHistorySupport ()\n    {\n        History.addHistoryListener (this);\n\n        // check to see if there are any tokens passed at startup via the browser’s URI\n        String token = History.getToken ();\n        if (token.length () == 0)\n        {\n            onHistoryChanged (INIT_STATE);\n        }\n        else\n        {\n            onHistoryChanged (token);\n        }\n    }\n\n\n    /**\n     * Fired when the user clicks the browser\'s \'back\' or \'forward\' buttons.\n     *\n     * @param historyToken the token representing the current history state\n     */\n    public void onHistoryChanged (String historyToken)\n    {\n        RootPanel.get ().clear ();\n        Page page;\n        if (Page1.TOKEN.equalsIgnoreCase (historyToken))\n        {\n            page = new Page1 ();\n        }\n        else if (Page2.TOKEN.equalsIgnoreCase (historyToken))\n        {\n            page = new Page2 ();\n        }\n        else if (Page3.TOKEN.equalsIgnoreCase (historyToken))\n        {\n            page = new Page3 ();\n        }\n        RootPanel.get ().add (page);\n    }\n}\n</code></pre>\n'}, {'answer_id': 72118, 'author': 'pjesi', 'author_id': 1296737, 'author_profile': 'https://Stackoverflow.com/users/1296737', 'pm_score': 3, 'selected': True, 'text': '<p>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.</p>\n\n<p>A portlet controller is pretty much the same as a servlet controller, here is a simple example:</p>\n\n<pre><code>@RequestMapping("VIEW")\n@Controller\npublic class NewsPortlet {\n\n    private NewsService newsService;\n\n    @Autowired\n    public NewsPortlet(NewsService newsService) {\n        this.newsService = newsService;\n    }\n\n    @RequestMapping(method = RequestMethod.GET)\n    public String view(Model model) {\n        model.addAttribute(newsService.getLatests(10));\n        return "news";        \n    }\n}\n</code></pre>\n\n<p>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.</p>\n\n<p>The XML configuration only needs to specify where the view and controllers are located:</p>\n\n<pre><code>&lt;!-- look for controllers and services here --&gt;\n&lt;context:component-scan base-package="com.example.news"/&gt;\n\n&lt;!-- look for views here --&gt;\n&lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;\n    &lt;property name="prefix" value="/WEB-INF/jsp/news/"/&gt;\n    &lt;property name="suffix" value=".jsp"/&gt;\n&lt;/bean&gt;\n</code></pre>\n\n<p>If you want to simply embed the portlets in your existing application, the you can bundle a portlet container, such as <a href="http://www.exoplatform.com" rel="nofollow noreferrer">eXo</a>, <a href="https://portlet-container.dev.java.net/" rel="nofollow noreferrer">Sun</a>, or <a href="http://portals.apache.org/pluto/" rel="nofollow noreferrer">Apache</a>. 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 <a href="http://liferay.com" rel="nofollow noreferrer">Liferay Portal</a>.</p>\n'}, {'answer_id': 81311, 'author': 'Andrew Swan', 'author_id': 10433, 'author_profile': 'https://Stackoverflow.com/users/10433', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not 100% sure what "reusable components" means in this context, but if you mean that you want certain common elements to appear on every page, such as banner, footer, navigation links, etc., then look no further than <a href="http://www.opensymphony.com/sitemesh/" rel="nofollow noreferrer">SiteMesh</a>. My team has used it successfully on a couple of internationalised web applications.</p>\n'}, {'answer_id': 425546, 'author': 'bpapa', 'author_id': 543, 'author_profile': 'https://Stackoverflow.com/users/543', 'pm_score': 2, 'selected': False, 'text': '<p>I don\'t recommend using Portlets unless your application is truly a <a href="http://en.wikipedia.org/wiki/Web_portal" rel="nofollow noreferrer">web portal</a>. </p>\n\n<p>If you just want "reusable components" use <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags5.html" rel="nofollow noreferrer">JSP tagfiles</a>, they are dead simple yet extremely powerful, since they are the same as regular JSPs.</p>\n\n<p>I\'ve had experience using tiles and the complexity involved simply isn\'t worth it. </p>\n'}, {'answer_id': 1159979, 'author': 'Phil Gounbin', 'author_id': 141286, 'author_profile': 'https://Stackoverflow.com/users/141286', 'pm_score': 1, 'selected': False, 'text': "<p>I had a lot of experience with portlets in conjunction with Ajax JSF (IceFaces) and Liferay Portal and I wouldn't recommend them to anyone - everything looks good when reading tutorial and real hell in practice. Of course I think they are much more convenient and lightweight with Spring MVC and JSP, but anyway, portlets aren't well supported technology imho.</p>\n"}]
['https://Stackoverflow.com/questions/71692', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11890/']