In order to facilitate updates to multi-valued profile properties, the ProfileFormHandler provides the addMulti
operation. This operation appends a new value to a multi-valued property in the ProfileFormHandler's
value
Dictionary. addMulti
can add multiple primitive values to types array
, set
and list
. The addMulti
feature cannot handle multiple Map
type values, or multiple items, as opposed to primitive data. To add multiple items, you must write your own form handler, as described in the Working with Forms and Form Handlers chapter of the Platform Programming Guide.
Unlike the other ProfileFormHandler operations, addMulti
does not update the user profile when its submit button is clicked. Instead, it appends the entered value to the value
Dictionary. Thus, the form user can add multiple values to the property before submitting them. Therefore, a page that implements an addMulti
submit button must also provide a submit button that creates or updates the user profile.
The following code shows how a form might contain an addMulti
operation:
<dsp:select multiple="true" bean="ProfileFormHandler.value.interests" name="interests" size="4"> <dsp:droplet name="ForEach"> <dsp:param bean="ProfileFormHandler.value.interests" name="array"/> <dsp:oparam name="output"> <dsp:option paramvalue="element" selected="true"/><dsp:valueof param="element">null</dsp:valueof> </dsp:oparam> </dsp:droplet> </dsp:select> <dsp:input name="Add Interests" type="hidden" value="AddMultiProperty_interests, AddMultiValue_interests"/> <dsp:input name="AddMultiProperty_interests" type="hidden" value="interests"/> <dsp:input name="AddMultiValue_interests" type="text"/> <dsp:input bean="ProfileFormHandler.addMulti" name="addMultiProperty" type="submit" value="Add Interests">
This code example contains the following steps:
The dsp:select tag specifies how many values for the
interests
field are available in the form.The ForEach servlet bean iterates through the array of Strings specified in the
bean.ProfileFormHandler.value.interests
parameter. If an interest is selected, it outputs the value; otherwise, it outputs null as the interest element value.A hidden input tag defines two text strings; these strings link the next two subsequent input tags:
AddMultiProperty_interests
is referenced by a hidden input tag’sname
attribute; this input tag’svalue
attribute identifies the target Dictionary property.AddMultiValue_interests
is referenced by the text input tag’sname
attribute. Form users use this field to enter new values for the target property.
The tag’s
name
attribute is set toAdd Interests
; this links the Dictionary property and text input field with theaddMulti
submit button.The tag that defines the
addMulti
submit button must set itsname
andvalue
attributes as follows:name
must be set toaddMultiProperty
value
must be set toAdd Interests
Note: In order to enable addMulti
operations for several multi-valued properties on the same page, each property must have its own pair of unique identifiers as described above, and a unique string for its submit button’s value
attribute.