On Jun 3, 2008, at 12:41 PM, Dan Olsen wrote:

So I have the following line of code:

DataSource ds = DataSourceFactory.getInstance();

Should I now be able to call ds.getConnection()? I do this and I am getting errors saying my connection is null.



Its not clear whether you are working from within the Jetspeed webapp, or another portlet application If you are writing portal code (inside Jetspeed), I recommend simply using Spring to wire it together
There are plenty of examples of that in the WEB-INF/assembly directory

I suspect you are probably working on your own web (portlet) application
In this case, you will not have access to Jetspeed's data source from you web app, nor will you have direct access to our spring container However we do provide Jetspeed Services for portlets. There a lots of examples of this in the j2-admin portlet application
Take a look at the jetspeed-portlet.xml for the j2-admin app:

        <js:services>
        <js:service name='ApplicationServerManager'/>
        <js:service name='DeploymentManager'/>
                <js:service name='EntityAccessor'/>
        <js:service name='GroupManager'/>
        <js:service name='PageManager'/>
        <js:service name='PermissionManager'/>
        <js:service name='PortletFactory'/>
        <js:service name='PortalAdministration'/>
        <js:service name='PortletRegistryComponent'/>
        <js:service name='PortalStatistics'/>
        <js:service name="Profiler" />
        <js:service name='RoleManager'/>
            <js:service name='SearchComponent'/>
        <js:service name="SSO" />
        <js:service name='UserManager'/>
        <js:service name='DecorationFactory'/>
        <js:service name='SecurityAccessController'/>
        <js:service name='PortletTrackingManager'/>
        <js:service name='PortalConfiguration'/>
        <js:service name='ImporterManager'/>
        <js:service name='AuditActivity'/>
        </js:services>

Here is an arbitrary example of using a Jetspeed service in a portlet's init:

    private PortalStatistics statistics;


    public void init(PortletConfig config) throws PortletException
    {
        super.init(config);
        PortletContext context = getPortletContext();
        statistics = (PortalStatistics) context
.getAttribute (CommonPortletServices.CPS_PORTAL_STATISTICS);
        if (statistics == null)
                throw new PortletException(
"Could not get instance of portal statistics component");
    }


and then perhaps in your processAction:

        ...
        DataSource ds = statistics.getDataSource();




Reply via email to