Specify a required field 




You can make a custom field into a required field by editing the validation.xml file.

About this task


IBM® Connections is built on Struts, allowing you to leverage the Struts validation framework to validate form data. The files validation.xml and validation-rules.xml are both part of the Struts validation framework. The validation.xml file defines the validation types that are applied to form fields; validation-rules.xml defines a set of standard validation routines. Validation routines, such as "required" and "maximum length", are included in the validation framework.

Note: Do not hide any required fields; if a user edits their profile contact information and required field information is hidden for that user type, the edited profile form cannot be saved.

Procedure


To make a custom extension field a required field, perform the following steps.


3. Add the following code to the validation.xml file to enable the Struts validator to recognize the tab that you are editing.

  1. Save a copy of the <was_profile_root>\installedApps\<cell_name>\profiles.ear\lc.profiles.app.war\WEB-INF\validation.xml file.

  2. Open the file in a text editor, and specify your validation requirements using the information in the following table.
    Attribute Role
    property The name of the field that you want to make required. You obtain the field name by viewing the source of the rendered page.
    depends The name of the validation to run.
    msg name Overrides the default required error message. This value matches the validator's name attribute.
    msg key The message to be displayed if the validation fails. The key in the property file contains the error message to display if validation fails. You need to add the key to the property file.

      Table 1. Validator attributes

      For example:

      <form-validation>
      <formset> <form name="editProfileForm"> <field property="attribute(contactInformation.extattr.property1)" depends="required"> <msg name="required" key="errors.required" /> </field> <field property="attribute(associatedInformation.description)" depends="maxlength"> <msg name="maxlength" key="errors.aboutMe" /> <var> <var-name>maxlength</var-name> <var-value>1500</var-value> </var> </field>

    <form-validation>
    <formset> <form name="editProfileForm"> <field property="attribute(contactInformation.extattr.property1)" depends="required"> <msg name="required" key="errors.required" /> <var> <var-name>subEditForm</var-name> <var-value>contactInfo</var-value> </var> </field> <field property="attribute(associatedInformation.description)" depends="maxlength"> <msg name="maxlength" key="errors.aboutMe" /> <var> <var-name>maxlength</var-name> <var-value>1500</var-value> </var> <var> <var-name>subEditForm</var-name> <var-value>aboutMe</var-value> </var> </field>

  4. Define a label for the required field. To do so, make a note of the ID of the extension, which is the value after the .extrattr. in the attribute definition for the field.

For example, the value for this field is property1:
<field property="attribute(contactInformation.extattr.property1)" ...>
Set the extensionIdRef attribute of the element that you use to define the field in the profiles-config.xml file equal to the value you noted here. See Enable custom extension attributes for Profiles for more details.
You should define a label for any custom fields that you add, but it is especially important to define a label for a required field because if the user does not enter a value in the field, but tries to save the form, a message is displayed telling them that x is required, where the x is the field label. If you do not define a label for the field, the term "null" is used instead. As a result, users will see a "null is required" message when they try to save the page, and will not know which field to fill in before they can save the page successfully.  


Parent topic

Add custom extension attributes for Profiles Related tasks: Enable custom extension attributes for Profiles  

    • <var>
      <var-name>subEditForm</var-name> <var-value>sectionName</var-value> </var>

      where sectionName is one of the following values:

      • contactInfo. For contact or job information fields.

      • aboutMe. For associated information fields.

      For example:


+

Search Tips   |   Advanced Search