[Building Sakai] [Building Sak ai] SiteService GetSi tes -throws NullPoint erEx ception
Steve Swinsburg
s.swinsburg at lancaster.ac.uk
Thu Jun 4 07:39:44 PDT 2009
Hi Mak,
Ok found the problem. In your faces-config managed-bean section for
your JSF backing bean
(org.sakaiproject.adaptivelearningsystem.tool.jsf.AdaptiveSiteBean),
you need to set your own service beans as a <managed-property>.
Try this:
<!-- Backing Bean -->
<managed-bean>
<description>AdaptiveLearningSystem Tool: AdaptiveSiteBean
Bean</description>
<managed-bean-name>AdaptiveSiteBean</managed-bean-name>
<managed-bean-
class
>org.sakaiproject.adaptivelearningsystem.tool.jsf.AdaptiveSiteBean</
managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<description>AdaptiveLearningSystem API</description>
<property-name>adaptiveLearningSystem</property-name>
<
value
>
#{org_sakaiproject_adaptivelearningsystem_api_AdaptiveSystemServiceInterface
}</value>
</managed-property>
</managed-bean>
Repeat for other services you want to inject into your Backing Bean.
In the actual bean, you'll then have:
private AdaptiveSystemServiceInterface myService;
public void setMyService(AdaptiveSystemServiceInterface myService) {
this.myService = myService;
}
That should do the trick.
cheers,
Steve
---
Steve Swinsburg
Portal Systems Developer
Centre for e-Science
Lancaster University
Lancaster
LA1 4YT
email: s.swinsburg at lancaster.ac.uk
phone: +44 (0) 1524 594870
On 4 Jun 2009, at 15:06, m_yaghmaie at modares.ac.ir wrote:
> Hi Steve,
>
> Thanks for your help,
>
> 1) This is how I injected the SiteService:
> <beans>
> <bean
> id
> =
> "org
> .sakaiproject
> .adaptivelearningsystem.api.AdaptiveSystemServiceInterface"
>
> class
> =
> "org.sakaiproject.adaptivelearningsystem.impl.AdaptiveSystemService"
> init-method="init">
> <property name="functionManager"
> ref="org.sakaiproject.authz.api.FunctionManager" />
> <property name="securityService"
> ref="org.sakaiproject.authz.api.SecurityService" />
> <property name="sessionManager"
> ref="org.sakaiproject.tool.api.SessionManager" />
> <property name="siteService"
> ref="org.sakaiproject.site.api.SiteService" />
> <property name="toolManager"
> ref="org.sakaiproject.tool.api.ToolManager" />
> <property name="userDirectoryService"
> ref="org.sakaiproject.user.api.UserDirectoryService" />
> </bean>
> </beans>
>
> private org.sakaiproject.site.api.SiteService siteService;
> public void setSiteService(SiteService siteService) {
> this.siteService = siteService;
> }
>
> 2) This is the web.xml I use:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- This file generated by Sakai App Builder -AZ -->
> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
> "
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
> "
> version="2.4">
> <display-name>sakai-adaptivelearningsystem</display-name>
> <description>Sakai AdaptiveLearningSystem</description>
>
> <context-param>
> <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
> <param-value>client</param-value>
> </context-param>
>
> <context-param>
> <param-name>com.sun.faces.validateXml</param-name>
> <param-value>false</param-value>
> </context-param>
>
> <context-param>
> <param-name>com.sun.faces.verifyObjects</param-name>
> <param-value>false</param-value>
> </context-param>
>
> <!-- Sakai request filter -->
> <filter>
> <filter-name>sakai.request</filter-name>
> <filter-class>org.sakaiproject.util.RequestFilter</filter-
> class>
> </filter>
> <filter-mapping>
> <filter-name>sakai.request</filter-name>
> <servlet-name>FacesServlet</servlet-name>
> <dispatcher>REQUEST</dispatcher>
> <dispatcher>FORWARD</dispatcher>
> <dispatcher>INCLUDE</dispatcher>
> </filter-mapping>
>
> <!-- Tool Servlet -->
> <servlet>
> <!-- servlet name must match tool.id in tools xml file -->
> <servlet-name>sakai.adaptivelearningsystem</servlet-name>
> <servlet-class>org.sakaiproject.jsf.util.JsfTool</servlet-
> class>
> <init-param>
> <param-name>default</param-name>
> <param-value>welcome</param-value>
> </init-param>
> <init-param>
> <param-name>path</param-name>
> <param-value>/adaptivelearningsystem</param-value>
> </init-param>
> <init-param>
> <param-name>default.last.view</param-name>
> <param-value>true</param-value>
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
>
> <!-- Faces Servlet -->
> <servlet>
> <servlet-name>FacesServlet</servlet-name>
> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
> <load-on-startup>2</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>FacesServlet</servlet-name>
> <url-pattern>*.jsf</url-pattern>
> </servlet-mapping>
>
> <!-- Sakai listeners -->
> <listener>
> <listener-class>org.sakaiproject.util.ToolListener</listener-
> class>
> </listener>
> <listener>
> <listener-class>org.sakaiproject.util.ContextLoaderListener</
> listener-class>
> </listener>
>
> </web-app>
>
> 3) And this is my faces-config
> <?xml version="1.0"?>
> <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD
> JavaServer Faces Config 1.0//EN"
> "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
>
> <!-- This file generated by Sakai App Builder -AZ -->
> <faces-config>
>
> <!-- Navigation Rules -->
> <navigation-rule>
> <from-view-id>/adaptivelearningsystem/welcome.jsp</from-view-
> id>
> <navigation-case>
> <from-outcome>success</from-outcome>
> <to-view-id>/adaptivelearningsystem/select-site.jsp</to-
> view-id>
> </navigation-case>
> </navigation-rule>
> <navigation-rule>
> <from-view-id>/adaptivelearningsystem/select-site.jsp</from-
> view-id>
> <navigation-case>
> <from-outcome>success</from-outcome>
> <to-view-id>/adaptivelearningsystem/select-page.jsp</to-
> view-id>
> </navigation-case>
> </navigation-rule>
> <navigation-rule>
> <from-view-id>/adaptivelearningsystem/select-page.jsp</from-
> view-id>
> <navigation-case>
> <from-outcome>success</from-outcome>
> <to-view-id>/adaptivelearningsystem/select-site.jsp</to-
> view-id>
> </navigation-case>
> </navigation-rule>
>
> <!-- Backing Bean -->
> <managed-bean>
> <description>AdaptiveLearningSystem Tool: AdaptiveSiteBean
> Bean</description>
> <managed-bean-name>AdaptiveSiteBean</managed-bean-name>
> <managed-bean-
> class
> >org.sakaiproject.adaptivelearningsystem.tool.jsf.AdaptiveSiteBean</
> managed-bean-class>
> <managed-bean-scope>session</managed-bean-scope>
> <!-- <managed-property>
> <description>User Directory Service</description>
> <property-name>userDirectoryService</property-name>
>
> <value>#{org_sakaiproject_user_api_UserDirectoryService}</value>
> </managed-property> -->
> </managed-bean>
>
> </faces-config>
>
> I am sorry for this long post,
> Tnx alot, Mak
> ---- Original Message ----
> From: Steve Swinsburg <s.swinsburg at lancaster.ac.uk>
> To: m_yaghmaie at modares.ac.ir
> Cc: sakai-dev at collab.sakaiproject.org
> Sent: Thu, Jun 4, 2009, 5:14 PM
> Subject: Re: [Building Sakai] SiteService GetSites -throws
> NullPointerEx ception
>
> Hi Mak,
>
> How have you injected siteService into AdaptiveSystemService? And
> then, how have you set AdaptiveSystemService into AdaptiveSiteBean?
>
> NPE's like these are commonly caused by the dependencies not being
> configured correctly. Post your pack's components.xml, and your tool's
> web.xml, applicationContext.xml, and faces-config.xml (if using JSF)
>
> cheers,
> Steve
>
>
>
> On 4 Jun 2009, at 13:38, m_yaghmaie at modares.ac.ir wrote:
>
> > Hi,
> >
> > I am trying to load all sites in order to show them in my Tool. I am
> > using SiteService and I call the following service:
> >
> > siteService.getSites(SiteService.SelectionType.PUBVIEW, null, "",
> > null, SiteService.SortType.ID_DESC, null);
> > This invocation throws NullPointerException:
> >
> > caused by: java.lang.NullPointerException
> > at
> > org
> > .sakaiproject
> > .adaptivelearningsystem
> > .impl.AdaptiveSystemService.getAllSites(AdaptiveSystemService.java:
> > 108)
> > at
> > org
> > .sakaiproject
> > .adaptivelearningsystem
> > .tool.jsf.AdaptiveSiteBean.getSites(AdaptiveSiteBean.java:54)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at
> > sun
> > .reflect
> > .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >
> > I passed the arguments according to the JavaDoc I found in the
> > SiteServiceAPI. Is there anything wrong with my code?
> >
> > Tnx, Mak
> > _______________________________________________
> > sakai-dev mailing list
> > sakai-dev at collab.sakaiproject.org
> > http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
> >
> > TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org
> > with a subject of "unsubscribe"
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org
> with a subject of "unsubscribe"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20090604/6b70b961/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2437 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20090604/6b70b961/attachment.bin
More information about the sakai-dev
mailing list