Announcement Announcement Module
Collapse
No announcement yet.
Lookup from JSP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lookup from JSP

    Hi

    I am using Spring 3 and want to access a Spring bean that holds the ref data. I do not want reference 'data' cached in application or session scope as I don't want it replicated across servers, or risk it being serialized, so I want the ref data to remain 'owned' by the Spring singleton bean.

    Can I use:

    #{referenceDataBean.refData} from JSP page?


    2)

    I am also thinking of using a session scoped bean to hold all user session data, and then providing a method in there to access reference data from a JSPX page.

    ie. provide a method on my UserSessionData (session scoped) bean, of accessing the service (

    oltpMethod() {

    // Would this be slow? if called many times per user page render

    ApplicationContext beanFactory =
    WebApplicationContextUtils
    .getRequiredWebApplicationContext(getServletContex t());
    RefDataService refDataService = beanFactory.getBean("refDataService");
    return refDataService.getRefData();


    }


    How performance is this method of looking up a Spring bean:

    ApplicationContext beanFactory =
    WebApplicationContextUtils
    .getRequiredWebApplicationContext(getServletContex t());


    Is it designed to be called once by a bean / class on startup / init, or it is ok to do the above?

  • #2
    1 simple answer, don't....

    Let the controller prepare the model and simply use the data. You in general don't want to call methods on application beans in your view. Try to keep it as decoupled from your logic as needed.

    Comment


    • #3
      Controller preparing the data

      Hi Marten,

      Thanks for your response. If you are suggesting the controller prepares the data and puts it into the parameter map, then this means every single controller method would have code in it to make the ref data available (we do have a Base Controller so could add a superclass method to do this.....). Is this what you are suggesting:



      public ModelAndView preparePage() {

      return super.returnModelAndViewWithRefData("path/toPage", currentMap);

      }


      ****************

      protected ModelAndView returnModelAndViewWithRefData(final String path, Map map) {
      map.put("refData", getRefData());
      return map;
      }


      ?


      Your suggestion would mean that every single controller method would have to

      Comment


      • #4
        Please use [ code][/code ] tags when posting code.

        That is what I meant... I also suggest a read of the reference guide on how to make it easier (@ModelAttribute). If you have shared data you can either put that on a base class or create a HandlerInterceptor which gathers all shared data... That is design wise (MVC / MVP pattern) the best solution...

        Comment

        Working...
        X