Announcement Announcement Module
Collapse
No announcement yet.
Page with some simple blocks Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Page with some simple blocks

    I have a question.

    Request from client → handler mapping → controller → view resolver – view (jsp).
    This scheme works perfect.

    We have page with some simple blocks (like news, etc).
    How initialize data in those blocks?

    1. We can't do it in controller because those blocks in view but controller do not know that view will be (it just mapping data to model).
    2. Always placing data in interceptors and/or some base controller is wrong. Those blocks do not visible every time.
    3.Best way is call “something” from view (jsp) that call controller (like newsController) that newsController mapping data to model and placing view (jsp segment) to parent view (from we call “something”).

    May be something of that already exists?
    May be exists other solution for this problem.

    Thanks.

  • #2
    I don't think the Contoller needs to know what view it is preparing data for. The view, or views, need to know the names of the data.

    A Controller can call the ModelAndView's addObject() method many times to put multiple objects in the Model. It can even add the same object in multiple times with different names. The view does not have to get all the Objects, just the ones it needs.

    Comment


    • #3
      Originally posted by redcayuga View Post
      I don't think the Contoller needs to know what view it is preparing data for. The view, or views, need to know the names of the data.
      I wrote:

      > 1. We can't do it in controller because those blocks in view but controller do not know that view will be (it just mapping data to model).

      It does meen that Controller not only don't need to know what view is preparing data for - it really does not know it.

      Originally posted by redcayuga View Post
      A Controller can call the ModelAndView's addObject() method many times to put multiple objects in the Model.
      Problem is not in mapping object. The problem is that view can have some small block and we must prepare data for them.

      Originally posted by redcayuga View Post
      It can even add the same object in multiple times with different names. The view does not have to get all the Objects, just the ones it needs.
      Yes. And this IS PROBLEM. We must add all object to model because we don't know what objects will use view. It is wrong and too heavy.

      I think view must call "controllers" (or something else) to output small blocks (like news, etc)

      Comment


      • #4
        It seems that your architecture violates the MVC concept. The View is supposed to render (display, print, etc.) the data without much control logic. The Controller is supposed to direct flow of control. I think you need to move logic from your "view" into your controller.

        What is your View? Is it a jsp with a lot of java in <% %> tags? If so, move logic into your Controller. Your controller can set a lot of "Yes/No" attributes in the Model that the view can use to decide what to display. That way, the complicated logic is in one place, in the Controller.

        Comment


        • #5
          Originally posted by redcayuga View Post
          It seems that your architecture violates the MVC concept. The View is supposed to render (display, print, etc.) the data without much control logic. The Controller is supposed to direct flow of control. I think you need to move logic from your "view" into your controller.
          View does not have a logic.

          Originally posted by redcayuga View Post
          What is your View? Is it a jsp with a lot of java in <% %> tags?
          No, it doesn't.

          Originally posted by redcayuga View Post
          If so, move logic into your Controller. Your controller can set a lot of "Yes/No" attributes in the Model that the view can use to decide what to display. That way, the complicated logic is in one place, in the Controller.
          Ok. I try to explain my position.

          We have a page with some count of small blocks. May be it is a page of login. Controller contains logic to login user, let's call it LoginController. LoginController does know only how to check user (and some same actions) and initialize data for “some view” (because LoginController does not know what view is will be).
          View has a block of news and… temperature. What is your idea? Your idea is insert into LoginController some logic to initialize data for news and temperature. I correctly formulated your idea?



          I try to understand how to initialize data for news and temperature.
          Only one idea what I have is call Controller from View.

          User request -> LoginController -> LoginView
          In LoginView (jsp) will be blocks like those:

          <spring:controller name=”news” />

          <spring:controller name=”news”>
          <property name=”view” value=”newsLayout” />
          </spring:controller>
          Last edited by polizay; Feb 6th, 2009, 01:11 AM.

          Comment


          • #6
            Yes, I'm saying that you should add logic to the LoginController. If you want to keep the LoginController simple it can merely redirect to a new Controller, I'll call it PostLoginController, to make all the complicated decisions. The PostLoginController creates all the needed Objects, and only what is needed, and redirects to the appropriate view.

            The point I'm trying to make is that some piece of code, somewhere, makes a decision and redirects to a particular view. Or maybe there's only one view and pieces are turned on and off with <c:if> or <c:choose> tags. In either case, all the information needed to make these decisions is in the request parameters, request attributes, or session attributes. This info is available to Controllers as well as Views. You may be using the info to do a database look up but that can also be done in a Controller.

            I'm not familiar with the <spring:controller> tag so I can't comment on that.

            Comment

            Working...
            X