Sakai Properties Exercise

These steps outline a basic approach for calling the Server Configuration Service from within a stock Hello World application created using the Sakai App Builder plugin for eclipse. The Server Configuration Service provides information about the server itself, including any custom properties used by our application.

  1. Create a new RSF Hello World app using the App Builder.
  2. Add the component-api to the build path.
  3. Add the following code to the template tool/src/webapp/templates/HelloWorld.html:
    <div rsf:id="optional-block:">
    You have set myPropertyString to &quot;<span rsf:id="property-value">value</span>&quot;.
    </div>
    
  4. Add the following code to the producer HelloWorldProducer.java:
    within the class itself:
    private ServerConfigurationService serverConfigurationService;
    public void setServerConfigurationService(ServerConfigurationService serverConfigurationService) {
    	this.serverConfigurationService = serverConfigurationService;
    }
    and within the fillComponents method:
    User currentUser = userDirectoryService.getCurrentUser();
    UIOutput.make(tofill, "current-displayname", currentUser.getDisplayName());
    UIOutput.make(tofill, "current-email", currentUser.getEmail());
    
  5. Add the injection to tool/src/webapp/WEB-INF/requestContext.xml:
    <property name="serverConfigurationService" ref="org.sakaiproject.component.api.ServerConfigurationService"/>
  6. Add the dependency to tool/project.xml (show them how to figure out the artifactId:
    <dependency>
    	<groupId>sakaiproject</groupId>
    	<artifactId>sakai-user-api</artifactId>
    	<version>${sakai.version}</version>
    </dependency>
    
    <dependency>
    	<groupId>sakaiproject</groupId>
    	<artifactId>sakai-component-api</artifactId>
    	<version>${sakai.version}</version>
    </dependency>
    
  7. Compile and test.

Download the full source code for the completed exercise if you want to see the results in action.