Chapter 5. KNS

Table of Contents

KNS Configuration Guide
Database Creation
KNSConfigurer and RiceConfigurer
Configuring the KNS Web Application Components
Module Configuration – Loading Data Dictionary and OJB Files
KNS Configuration Parameters
KNS Business Object Framework
Business Object Database Table Definition
Business Object Java Definition
KNS Data Dictionary Overview
Business Object Data Dictionary
Document Data Dictionary Overview
Maintenance Document Data Dictionary Overview
Alternate/Additional Display Properties
Dynamic read-only, hidden, and required Field states
Configuring a KNS Client in Spring
Spring JTA Configuration
KNS Validation and Business Rules Framework
Rules and Events
Standard KNS Events
Notifying Users of Errors
Creating New Events
KNS User Messages
Retrieving User Messages
Error Messages
Struts Messages
KNS Questions and Dialogs
Prompting Before Validation
HTML Markup
Derived Values Setters
KNS Notes and Attachments
KNS Javascript Guide
Integrating Javascript with KNS tags
Incorporating AJAX
KNS Data Masking
KNS Authorization
Common Document Authorizations
Maintenance Document Authorizations
Transactional Document Authorizations
Other Authorizations
Overriding Document Authorizers
KNS Exception Handling and Incident Reporting
KNS System Parameters
Getting text from a system parameter
Using an indicator parameter
Parameter Evaluators
Calling missing System Parameters
Overriding Rice Parameters
Building Screens using the KNS Tag Libraries
Implicit Variables
Tags for Layout
Tags for Controls
Tags for KNS Functionality
Useful Pre-Created Tabs

KNS Configuration Guide

The Kuali Nervous System (KNS) is, primarily, an application development framework. Each Rice client application can use the KNS to construct various screens and build pieces of the application with the built-in components and services that the KNS provides.

To this end, configuration of the KNS in a client application can be accomplished by following these steps:

  1. Creation of database tables in the client application’s database that the KNS requires to function.

  2. Loading of the KNSConfigurer inside of the RiceConfigurer Spring bean. This includes configuring connections to the databases.

  3. Loading of the KNS struts module for the various UI components that the KNS provides in addition to any filters or servlets that need to be defined in the client application’s web.xml.

  4. Creation of a ModuleConfiguration for the application which instructs the KNS about which Data Dictionary files and OJB repository mapping files to load.

  5. Customization of the various configuration parameters that the KNS supports.

Database Creation

In order for the KNS services to work, many of them require the ability to access special tables within the client application’s database. These tables are used to store various pieces of data; from notes and attachments on documents to maintenance document data and much more.

These tables are included as part of either the demo-client-dataset or the bootstrap-client-dataset. These datasets are provided with the Kuali Rice binary distributions and instructions on how to install them can be found in the Installation Guide.

Note

It’s important to note that these tables should be installed in the client application’s database, and not the Rice standalone server database.

KNSConfigurer and RiceConfigurer

As with the other modules, a KNSConfigurer needs to be injected into the RiceConfigurer in order to instruct Rice to initialize the KNS module. The main purpose of this is to allow for the applicationDataSource and the serverDataSource to be specified.

The applicationDataSource should point to the client application’s database. That database should contain the tables from one of the client datasets.

The serverDataSource should point to the database of the Rice standalone server. This is used for allowing access to the various KNS central services that use data in the Rice server database. This includes such data as System Parameters, Namespaces, Campuses, States and Countries.

Here is an example of Spring configuration for a KNS client:

<bean id="rice" class="org.kuali.rice.core.config.RiceConfigurer">
    ...
    <property name="knsConfigurer">
        <bean class="org.kuali.rice.kns.config.KNSConfigurer"
>
            <property name=”applicationDataSource” ref=”applicationDataSource”/>
            <property name=”serverDataSource” ref=”riceServerDataSource”/>
        </bean>
    </property>
    ...
</bean>

Alternatively, you can just set the dataSource and serverDataSource on the RiceConfigurer itself and that will be used for the KNS applicationDataSource and serverDataSource respectively. This is useful when using the same database for all the different modules of Rice.

The KNSConfigurer supports some other properties as well. See the javadocs of KNSConfigurer for more information.

Configuring the KNS Web Application Components

Loading the KNS Struts Modules

The web application framework of the KNS is built on top of the Apache Struts framework. As a result of this, the web application components of the KNS are loaded into the client application as a struts module. The struts module and various pieces of the Rice web content can be found in the binary distribution. They should be copied into the root directory of your web application.

A special implementation of the Struts ActionServlet is provided to help with the loading of the struts modules. It can be configured in the application’s web.xml as in the following example:

<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.kuali.rice.kns.web.struts.action.KualiActionServlet</servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
</servlet>

Notice the init-param above points to a Struts configuration file. This file is intended to be the struts configuration file for the client application. It’s used by the KNS for doing redirects back to the main application and is also used for adding KNS-based screens within the client application. Specifically, this is where action mappings go if using the transactional document framework of the KNS.

There is an example file in the distributions under config/examples/struts-config.example.xml. This will need to be renamed to struts-config.xml and copied to your web application’s WEB-INF directory. It can then be loaded using the KualiActionServlet as seen in the example above.

In this example file you will see a reference to a message resource properties file. As is the case with a standard Struts-based application, the resource properties file is used to load text strings for internationalization purposes. The KNS framework requires that at least the app.title property to be set, as in the following example:

app.title=Recipe Sample Application

Configuring KNS Servlet Context Listeners

The KNS framework requires a couple of ServletContextListener classes to be configured in the application’s web.xml. These include:

  • org.kuali.rice.kns.web.listener.JstlConstantsInitListener

  • org.kuali.rice.kns.web.listener.KualiHttpSessionListener

These should be included in the web.xml after any listeners or servlets that might be used to actually initialize the Spring context that loads Rice.

Here is an example of what this configuration might look like in web.xml:

<listener>
    <listener-class>my.app.package.ListenerThatStartsRice</listener-class>

</listener>


<listener>
    <listener-class>org.kuali.rice.kns.web.listener.JstlConstantsInitListener</listener-class>

</listener>



<listener>
    <listener-class>org.kuali.rice.kns.web.listener.KualiHttpSessionListener</listener-class>
</listener>

Configuring KNS Message Resources

As of Rice version 1.0.1.1, messages are loaded through the new KualiPropertyMessageResourcesFactory. This class is a factory of KualiPropertyMessageResources, which takes in a comma delimited list of .properties files.

This is set up in the struts-config.xml files near the end of the file:

<message-resources factory=”org.kuali.rice.kns.web.struts.action.KualiPropertyMessageResourceFactory” parameter=”” />

When the parameter above is set to an empty string, Rice uses the default value of properties files. The default value is set by the rice.struts.message.resources property the common-config-defaults.xml file. This is the default setting:

<param name=”rice.struts.message.resources”>KR-ApplicationResources,org.kuali.rice.kew.ApplicationResources,org.kuali.rice.ksb.messaging.ApplicationResources,KIM-ApplicationResources” />

This can be overridden in rice-config.xml. This value should be in a comma delimited format. The list of files is loaded from left to right, with any duplicated properties being overridden in that order. Therefore, in the list default list if a property key in KR-ApplicationResources was duplicated in KIM-ApplicationResources, the value used would be the one set in KIM-ApplicationResources.

Configuring AJAX Support

The KNS uses DWR to provide AJAX support. In order to enable this, the org.kuali.rice.kns.web.servlet.KualiDWRServlet must be configured in the application’s web.xml as follows:

<servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>org.kuali.rice.kns.web.servlet.KualiDWRServlet</servlet-class>
    <init-param>
        <param-name>debug</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>springpath</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

...

<servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

Module Configuration – Loading Data Dictionary and OJB Files

One of the most important pieces of the KNS framework is the Data Dictionary. It’s used to define various pieces of metadata about business objects, maintenance documents, lookups, inquiries and more. These Data Dictionary files are authored in XML and are loaded using a ModuleConfiguration. Additionally, business objects in the KNS are mapped to the database using an object relational mapping library called Apache OJB. The ModuleConfiguration is also used to load those mapping files.

A ModuleConfiguration is a bean wired in Spring XML that instructs the KNS to load various pieces of configuration for a particular module. A client application could create a single module or multiple modules, depending on how it is organized. This configuration allows for the specification of the following:

  • The module’s namespace

  • The Data Dictionary files to load

  • The OJB repository files to load

  • The package prefix of business objects in this module

  • Externalizable business object definitions

Here is an example of what this configuration might look like:

<bean id="sampleAppModuleConfiguration"
 class="org.kuali.rice.kns.bo.ModuleConfiguration">
    <property name="namespaceCode" value="tv"/>
    <property name="initializeDataDictionary" value="true"/>
    <property name="dataDictionaryPackages">
        <list>
            <value>classpath:edu/sampleu/travel/datadictionary</value>
        </list>
    </property>
    <property name="databaseRepositoryFilePaths">
        <list>
            <value>OJB-repository-sampleapp.xml</value>
        </list>
    </property>
    <property name="packagePrefixes">
        <list>
            <value>edu.sampleu.travel</value>
        </list>
    </property>
</bean>

When the module is initialized by the KNS, it will load all of the Data Dictionary files into the Data Dictionary service. Additionally, all OJB files will be loaded and merged into the main OJB repository. The packagePrefixes are used to identify which business objects this module is responsible for.

There are more configuration options on the ModuleConfiguration. See the javadocs on this class for more information.

KNS Configuration Parameters

The KNS supports numerous configuration parameters that can be set in the Rice configuration file. Below is a list of these with descriptions and defaults.

Table 5.1. KNS Configuration Parameters

Property Description Default
application.url Base URL of the application. Example: http://localhost/kr-dev${appserver.url}/${app.context.name}
attachments.directoryDirectory in which to store attachments /tmp/${environment}/attachments
attachments.pending.directoryDirectory in which to store attachments on a document or object which have not yet been persisted/tmp/${environment}/attachments/pending
classpath.resource.prefixThe location, in the classpath, of methods that may be called by DWR./WEB-INF/classes/
externalizable.help.urlBase URL at which web-based help content will be located/${app.context.name}/kr/static/help/
externalizable.images.urlBase URL at which images are located /${app.context.name}/kr/static/images/
kr.externalizable.images.urlBase URL at which images that are part of the standard Kuali Rice image set are stored /${app.context.name}/kr/static/images/
kr.urlBase URL of the KNS struts module. Includes the various built-in GUI components such as lookups, inquiries, etc. ${application.url}/kr
production.environment.codeThe environment code that will be used to identify this application as a “production” instance. Certain features are turned off in non-production instances (email, for example) PRD
mail.relay.serverName of the SMTP server to use for sending emails from the KNS 
kr.incident.mailing.listThe email address where exception and incident reports should be sent 
javascript.filesA comma-separated list of javascript files to load on every KNS-based web page See impl/src/main/resources/resources/META-INF/common-config-defaults.xml in the source distribution
css.filesA comma-separated list of css files to load on every KNS-based web pageSee impl/src/main/resources/resources/META-INF/common-config-defaults.xml in the source distribution
enable.nonproduction.data.unmaskingIf the current application is running in an non-production environment, this determines if all fields should be unmasked in the Nervous System, even if the field would otherwise be masked.false
kns.cache.parameter.max.sizeThe maximum number of parameters that can be stored in the kns parameter cache200
kns.cache.parameter.max.age.secondsThe maxiumum age (in seconds) of entries in the parameter cache 3600
kns.cache.nonDatabaseComponent.max.size The maximum size of the cache that is used to store parameter components that don’t come from the database (i.e. are loaded from the Data Dictionary and other locations) 50
kns.cache.nonDatabaseComponent.max.age.secondsThe maximum ago (in seconds) of entries in the parameter non-database component cache3600
session.document.cache.sizeThe max size of the cache used to store document sessions100
portal.javascript.filesA list of Javascript files to be included int the "portal", ie the frame around the application pages. 
portal.css.filesA list of CSS files to be used in the "portal", ie the frame around the application pages.rice-portal/css/portal.css
rice.kns.struts.config.filesThe struts-config.xml configuration file that the KNS portion of the Rice application will use./kr/WEB-INF/struts-config.xml
rice.kns.illegalBusinessObjectsForSaveA comma-separated list of business objects that the KNS should not be allowed to save 
rice.kns.illegalBusinessObjectsForSave.applyCheckIf set to true, the check for illegal business objects to save will be performed, if false, it will nottrue
encryption.keyThe DES key to use for encrypting data elements that are configured for encryption in the KNS 
rice.struts.message.resourcesThe key used to load message property files. The value should be a comma delimited list or properties files.KR-ApplicationResources,org.kuali.rice.kew.ApplicationResources,org.kuali.rice.ksb.messaging.ApplicationResources,KIM-ApplicationResources