title: Obtaining A Value From A DAO To Use in JSP
body: <p>I'm assuming this is very easy to do, but I've been searching for a couple hours on Google and StackOverflow with no luck.</p>
  
  <p>For starters, I have a jsp page using Dojo.  I use Dojo's request module to make AJAX calls to Spring controllers for all sorts of things.  The controllers call services, the services call DAOs, etc etc.</p>
  
  <p>Originally, I had a properties file that contained several configuration settings for my site.  These were injected into various Spring components using @Value.  I wanted to make these dynamically configurable from my admin page, so I added a domain object called "SiteSettings" that holds the values from my properties file.  When my webapp starts up, if it can't fine a SiteSettings object in persistence, it creates a new one, populates it with the settings from my properties file, and persists it.  If one is already in persistence, it just uses it.</p>
  
  <p>All of the site properties are used on the back-end except for one, a boolean called "authenticationRequired".  I need to access this value in a javascript value on the front-end.  This would be very easy to obtain via AJAX after the page loads, but I thought it's kind of silly to have to make an additional request, when I'm sure I should just be able to get the value from my SiteSettingsService (which uses the DAO to get the domain object).</p>
  
  <p>Right now, I'm getting the value directly from the properties file:</p>
  
  <pre><code>&lt;fmt:bundle basename="swtc"&gt;
       &lt;fmt:message key="swtc.authenticationRequired" var="authenticationRequired"/&gt;  
  &lt;/fmt:bundle&gt;    
  &lt;script type="text/javascript"&gt;
       window.authenticationRequired = &lt;c:out  value="${authenticationRequired}"/&gt;;
  &lt;/script&gt;
  </code></pre>
  
  <p>How can I modify this get the value from my service/dao/domain object instead of directly from my properties file?  Here are my controller and service files... nothing fancy:</p>
  
  <p>Controller:</p>
  
  <pre><code>@RequestMapping(value = "/getSiteSettings", method = RequestMethod.GET)
      @ResponseBody
      public ModelMap getSiteSettings(ModelMap model) {
          try {
              SiteSettings siteSettings = siteSettingsService.getSiteSettings();
              model.addAttribute("siteSettings", siteSettings);
              model.addAttribute("success", true);
          } catch (Exception ex) {
              logger.error("There was an error getting the site settings data. ", ex);
              model.addAttribute("exceptionMessage", ex.getLocalizedMessage());
              model.addAttribute("success", false);
          }
          return model;
      }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>@Override
      public SiteSettings getSiteSettings(){
          List&lt;SiteSettings&gt; siteSettings = siteSettingsDao.findAll();
          if (siteSettings != null &amp;&amp; !siteSettings.isEmpty()){
              return siteSettingsDao.findAll().get(0);
          }
          return null;
      }
  </code></pre>