Announcement Announcement Module
Collapse
No announcement yet.
Missing the connection between DispatcherPortlet and Controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Missing the connection between DispatcherPortlet and Controller

    Spring Portlet MVC 2.5.6
    I am missing the connection...if I am in class MyController extends AbstractController, how do I get at the DispatcherPortlet object? For example, if I wanted to call getUsernameForRequest() from the DispatcherPortlet object how would I do that? I understand DispatcherPortlet's job is to do as it's name implies, which in this case is to dispatch to MyController, I am just trying to understand. Thanks.

  • #2
    AFAIK there is no link back to the DispatcherPortlet from a Controller, and there really shouldn't be either.

    The method you have referred to is an example of something that might have been useful to have in PortletUtils, but it isn't. You could implement the exact same thing as a utility in a couple of lines of code if you need it - the main advantage of this method is the fallback option to use the portlet user attributes as another source of username if the request doesn't contain it (PortletRequest.getRemoteUser or PortletRequest.getUserPrincipal). Even if there is a link back to the DispatcherPortlet somewhere, you won't be able to access this method since it is protected.

    HTH, Chris

    Comment


    • #3
      What I had in mind was to extend DispatcherPortlet. So I would, for example, have class MyPortlet extends DispatcherPortlet. MyPortlet class has some utility type methods in it. I have done the same in the past, prior to using Spring, when extending javax.portlet.GenericPortlet. I could just do getSomeMethod() from any portlet, the method was always there without any effort. I was hoping to do the same for my Controllers.

      I will have approx 7 distinct portlets each having approx 5 controllers. So, based on my limited understanding of Spring, I would have to either inject this MyPortlet class 35 times in the bean config files or programmatically request it 35 times in each controller, either of which is ugly as it's up to each developer to make sure they are doing so. Isn't there a better way to accomplish this?

      Comment


      • #4
        I think you would be better to provide your own base Controller implementation(s) (e.g. extend SimpleFormContoller, etc) rather than trying to do this in the DispatcherPortlet.

        If you can use the new @Controller annotation configuration approach then you have greater flexibility since you don't have to extend the Spring base classes, so it is much easier to provide your own base class containing these sorts of utilities.

        Another alternative is to use a static utility class.

        Comment

        Working...
        X