How to get portlet preferences in init()?

Hi!
Is there a way to get portlet preferences during the first invocation in Application.init() ? Getting preferences inside PortletListener.handleRenderRequest works just fine. Inside method handleRenderRequest request.getPreferences(); does the trick.

The problem seems to be that PortletListener only gets called after the init()-method has returned.

So is there a way to get either ActionRequest or something else to get PortletPreferences inside Application.init()?

br,
Jarkko

Hi,

You are correct; Application.init() does not yet have access to portlet stuff. It’s possible that this could be changed in the future, but currently this is the way it works.
Right now, I can’t recall if something is actually preventing us from doing it differently, or if the reason is that it would require more portlet-specific changes to the application init logic (since init() does not have any parameters, we’d have to put the preferences somewhere, i.e context).

How badly do you need this? And more importantly: how would you like it to work? (Just preferences, or something else too? API suggestions?) We have not received a whole lot of feedback on the portal integration yet, but I’m sure there are lot’s of improvements that could be done to make it more fun to use…

Best Regards,
Marc

I’m not the original poster, but I have the same basic need.

My use case is that the application must be able to initialize the UI with reference to the effective portlet preferences, the user’s portal groups and roles, and the user’s application entitlements. For example, the main window of the Vaadin application portlet must display the results of a query on initial page load. The parameters of this query are set according to the user’s roles and associated application context. The initial columns and sort order of the resulting data table are selected according to the portlet preferences.

My understanding of Vaadin is that the main window and all components that will be available in the initial UI view presented to the user must be constructed (directly or indirectly) from the Application.init() method. However, the ApplicationContext returned from Application.getContext() when the application is running as a portlet is a PortletSessionContext. This context does not provide access to the PortletPreferences object, nor does it provide access to the remoteUser identifier. Both of these are only available from the PortletRequest object. As has been noted, the PortletRequest is available to a PortletListener’s event handler methods, but this comes too late to construct the initial UI.

JSF handles this by using a thread-local FacesContext instance. This will return an ExternalContext object, which makes application context, session context and request objects available. In the portal environment, these will be PortletContext, PortletSessionContext and PortletRequest types. Perhaps Vaadin could use a similar mechanism, since Application.init() and all event-handlers run in the context of a servlet request thread. ExternalContext even mediates the differences between the portlet environment and the servlet environment.

Some new API additions in Vaadin 6.2 (pre-version
here
, final version coming soon) may help you here.

If your Application implements PortletRequestListener (a new interface), the methods onStartRequest() and onEndRequest() are called with the request and the response. onStartRequest() is called before the application is started.