Accessing WSRP Consumer Registration Information Using the
.NET Portlet Toolkit
To identify a specific WSRP Consumer and access registration
information, use the RegistrationInfo class in
the .NET Portlet API.
By requiring registration, a WSRP Producer can request additional
information about a WSRP Consumer which can be used to tailor the
available portlets and resources. WSRP Consumer registration information
is available to WSRP portlets through the RegistrationInfo class in the .NET Portlet API.
- Configure the wsrp-producer.xml file to require registration,
and define any registration properties. (The ConsumerAgent, ConsumerName
and Handle are available by default.)
<?xml version="1.0"?>
<wsrp-producer xmlns="http://www.bea.com/al/dotnet/wsrpproducer/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<requires-registration>true</requires-registration>
<registration-properties>
<property name="ConsumerClass" type="xs:string">
<label lang="en">Consumer Class</label>
<hint lang="en" >the type of consumer</hint>
</property>
</registration-properties>
...
</wsrp-producer>
- Access the registration information using the RegistrationInfo class in the .NET Portlet API. You can
also use RegistrationPropertyAttribute to bind
a registration property to a page member variable (field).as shown
in the example below.
The RegistrationPropertyAttribute preference
attribute has two optional properties:
- Key: A string that provides the key name of the property to which
the member variable is bound. This value must match the value of the
name attribute for the registration property defined in the wsrp-producer.xml
configuration file. If this value is not defined, the key defaults
to the name of the member variable on which it is defined. If the
key value does not match a registration property defined in the wsrp-producer.xml
file, the member variable will use the default value. Key values must
be unique within a page.
- DefaultValue: A string that provides the value to use when the
preference is unavailable or has not yet been set. If this value is
not provided, it will default to a value based upon the type of the
variable as follows:
Property Type |
Default value if not assigned |
string |
String.Empty |
int, long |
0 |
double, float |
0.0 |
bool |
false |
DateTime |
DateTime.MinValue |
public partial class RegistrationPage : System.Web.UI.Page
{
protected RegistrationInfo registration = WSRPPortletContext.Current.ConsumerRegistration;
[RegistrationProperty(Key = "doubleProperty", DefaultValue = 32)]
protected double doubleProp;
protected void Page_Load(object sender, EventArgs e)
{
registrationTable.Rows.Add(getPrefRow("ConsumerAgent", registration.ConsumerAgent));
registrationTable.Rows.Add(getPrefRow("ConsumerName", registration.ConsumerName));
registrationTable.Rows.Add(getPrefRow("Handle", registration.Handle));
foreach (KeyValuePair<string, string> kvp in registration.Properties)
registrationTable.Rows.Add(getPrefRow("regprop:" + kvp.Key, kvp.Value));
registrationTable.Rows.Add(getPrefRow("RegistrationProperty:doubleProperty", doubleProp.ToString()));
}
...