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 Property | Description |
---|---|
|
The ID of the requesting user who wants to be friends. Needless to say, the property is required. |
|
The ID of the user with whom the requesting user wants to be friends with. The property is also required. |
|
The name of the content type of the message content that will be send to
the requested user (identified by |
|
Usually set to |
|
The form properties are field names of the content-type.
In our case, the |
|
The URL to which the user should be directed to when the friendship request becomes successful. |
|
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:
|