Requesting Friendships

The feature is provided by Struts framework action. The Action can be declared as follows:

<form-bean name="friendshipForm" type="com.ndc.community.struts.actions.forms.FriendshipForm"/>

<action path="/friendship/request"
        name="friendshipForm"
        scope="request"
        type="com.ndc.community.struts.actions.friendship.RequestFriendship">
        <forward name="error" path="/friendship-error.jsp" />
        <forward name="success" path="/" redirect="true />
</action>

An example JSP template to allow a user to invite any other user can be as follows:

<html:form action="/friendship/request"  method="post">
  <community:user id="currentUser"/>
  <community:user id="targetUser" userId="${param.userId}"/>

  <html:hidden property="userId" value="${currentUser.id}"/>
  <html:hidden property="friendId" value="${targetUser.id}"/>

  <html:hidden property="successUrl" value="${targetUser.section.url}" />
  <html:hidden property="errorUrl" value="${targetUser.section.url}?view=requestFriendship"/>

  <!-- Rest of the form fields related to textMessage content-type -->
  <html:hidden property="articleType" value="textMessage"/>
  <html:hidden property="state" value="published"/>
  Title: <html:text property="field(TITLE)"/><br/>
  Message: <html:text property="field(BODY)"/><br/>
  <html:submit>Request</html:submit>
</html:form>

The form properties above are explained as follows:

Form PropertyDescription

userId

The ID of the requesting user who wants to be friends. Needless to say, the property is required.

friendId

The ID of the user with whom the requesting user wants to be friends with. The property is also required.

articleType

The name of the content type of the message content that will be send to the requested user (identified by friendId).

state

Usually set to published since you will want the requested user see the message.

field(field-name)

The form properties are field names of the content-type. In our case, the textMessage content-type contains only two fields, Title and Body in the demo web-app.

successUrl

The URL to which the user should be directed to when the friendship request becomes successful.

errorUrl

The URL to which the user should be directed to if the friendship request results in an error. The errors are saved into request scope with different property names as follows:

RequestFriendship : if no friendId is given.

error : if the two users are already friends or an internal error has occured.

field(field-name) : the field for which validation error has occured.