Our next lesson will teach us how to load parameters with stored values. Change the highlighted lines in the process definition so that it looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<process>
...
<step id="compose" processor="hello">
<load parameter="username">
<value key=”user-agent” store=”request-header”/>
</load>
<load parameter="style">
<string>color:red;font:italic;</string>
</load>
</step>
...
</process>The value tag is very important as it enables you to access different stores that are provided by Projector. One of these stores is the request-header store. This store can be used to access header fields of the incoming HTTP request. In our example we will load the parameter username with the content of the request header field user-agent. Upload the changes and reload the page:
It worked! Instead of good old Tony or the date the content of the request header field user-agent is displayed. This might be of interest later as we could use this information to build a multi channel application that can display pages differently depending on the user-agent.
The following table will give you a brief overview of the available stores any their meaning. As we will use most stores in future examples you will get familiar with them very soon.
Table 7.2. Available stores
| Store | Description | HTTP specific |
|---|---|---|
| request-parameter | This store contains all parameters that have been encoded in the request URL. You cannot save any data to this store as this store is a read only. | X |
| request-attribute | If you want to save or access values that have a scope of a single HTTP-request you can use this store. This can be useful if you call a processor out of another web technology like Struts or JSP and want to share some request related information. | X |
| request-header | This store can be used to read the header fields of a HTTP-request. We already used this one to retrieve the user-agent header field. | X |
| Session | The session store is used to load or save values to the current session. The lifetime and clustering of sessions is done by the enclosing J2EE-container. | X |
| Context | The context store enables you to store information that will last for the scope of a single process invocation. It is comparable to the request-attribute store if you call a processor via HTTP but it will give the ability to call a processor without HTTP environment and will by this make it much more flexible and reusable. Use this store to share data between different processors in the same call. | |
| Cache | This store represents the transaction aware cache of Projector. You can share data not only between different processors in the same call but for a longer lifetime. So this is the right choice if you want to share data between different calls. This store is mostly used to cache rendered pages, page fragments or the result of time consuming search requests to speed up your application. | |
| Repository | This store gives you read and write access to the content that is stored in the underlying WebDAV-server. As the repository can be located on another machine and might be accessed via a secure connection as we have seen in the architectural overview, accessing this store can be slow. | |
| Input | Accessing the input parameters of your process is possible via the input store. You should not write any values to this store as it is available for retrieving the defined input parameters of your process. | |
| output | If you want to store results of your process, use the output store. This is a write only store and you should never try to read values from this store. Stored values will be available in scope of the enclosing process. | |
| Process | You can store data in scope of your process even if it spans multiple requests or pages in terms of HTTP. | |
| Persistent-process | This store is similar to the process store but will store the shared data in the underlying repository so that it will not be lost event if you start the Projector server. | |
| Form | The form store is used to store and retrieve data that is bound to a specific form. If you think of a web page that contains some forms, the state of each form is stored in the corresponding form store. | |
| Step | If you want to pass data from one processor step to the directly following step you can use the step store to do so. |
All stores that are marked as HTTP specific can be used to access the well known stores available in the J2EE world. So they are a good choice if you know that you process will be invoked from a HTTP call. Projector is able to call a process in background and when doing so the HTTP environment will not be available. Each process that makes use of these HTTP specific stores can’t be called in background and is limited to a HTTP based call. So try to avoid the use of these stores whenever possible.