Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The consideration of choosing ajax vs server-side operation should factor in on user experience, security etc -- not simply based on your development time. Some operation are more appropriate to be done on server side while other on client side / ajax. Keep in mind <a href="http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/" rel="nofollow">combining Spring with Jackson JSON processor</a> helps a lot when developing ajax, POJO can be mapped directly and returned via handler with minimal code.</p> <p>I wouldn't go with iframe because difficulty of integrating client side items with other components of the page</p> <p>With regards to having duplicate codes on different controllers, one approach that has worked for me is a common superclass controller approach:</p> <p>Create a superclass controller that contains shared reusable code (eg: to enrich widget model)</p> <pre><code>public class CommonController { @ModelAttribute public void enrichWidgetA(Model model) { model.addAttribute("widgetAMsg", "hello world"); } } </code></pre> <p>Extend CommonController on other controller classes</p> <pre><code>@Controller public class HomeController extends CommonController { @RequestMapping("/home") public String home() { // do your stuff here return "home"; } } </code></pre> <p>On your JSP view you can <a href="http://gerrydevstory.com/2013/07/16/creating-reusable-html-using-jsp-tag/" rel="nofollow">utilize JSP tag to keep it DRY</a> (Donot Repeat Yourself). <code>enrichWidgetA</code> will be invoked prior to <code>home()</code> handler method and you can perform business operation for the reusable view component.</p> <p>Ofcourse the downside of this approach is if you have multiple widget but only some (not all) appear on the page, every single method on <code>CommonController</code> decorated with <code>@ModelAttribute</code> still runs anyway.</p> <p>If this is not desirable maybe you can improve this pattern by setting some flags in constructor so the superclass knows which widget enrichment method should (not) be run.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload