18.3.3. Example 3: adding new properties

Note

Please make sure you read at least the section about user profile configuration: Section 17.3, “User profile configuration”, to add a new value on the interface it also has to be defined in your model, as shown on Step 1.
step 1: add a new property to profile-config.xml e.g. a dynamic property called gender:
...
   <property>
      <name>user.gender</name>
      <type>java.lang.String</type>
      <access-mode>read-write</access-mode>
      <usage>optional</usage>
      <display-name xml:lang="en">Gender</display-name>
      <description xml:lang="en">The gender</description>
      <mapping>
         <database>
            <type>dynamic</type>
            <value>user.gender</value>
         </database>
      </mapping>
   </property>
...

Note

It is recommended to use the 'User Information Attribute Names' from the Portlet Specification for defining properties.
step 2: add the property to the identity-ui-configuration: (portal-identity.sar/conf/identity-ui-configuration.xml)
...
    <ui-component name="gender">
        <property-ref>user.gender</property-ref>
        <required>true</required>
        <values>
            <value key="male">Male</value>
            <value key="female">Female</value>
        </values>
    </ui-component>
...

Note

The property-ref must match a property from the profile-config.xml.
step 3: add your custom ui-component to the profile page: (portal-identity.sar/portal-identity.war/WEB-INF/jsf/profile.xhtml)
...
    <h:outputText value="#{bundle.IDENTITY_GENDER}"/>
    <h:selectOneMenu id="gender" value="#{manager.uiUser.attribute.gender}"
            required="#{metadataservice.gender.required}">
        <f:selectItems value="#{metadataservice.gender.values}" />
    </h.selectOneMenu>
    <h:panelGroup />
    <h:message for="gender"/>
...

Note

Don't forget to add the localization elements.