Creating Articles

The section explains how a developer can implement a feature that allows a user to create an arbitrary article.

<form-bean name="articleForm" type="com.ndc.usercontent.struts.actions.forms.ArticleForm" />

<action path="/content/add"
        name="articleForm"
        scope="request"
        parameter="articleType=blog;allowSetPublishDate=true;allowSetActivateDate=true;allowSetExpireDate=true"
        type="com.ndc.usercontent.struts.actions.save.SaveArticle">
    <forward name="success" path="/create-content-success.jsp" />
    <forward name="error" path="/create-content.jsp" />
</action>

Please note the parameter attribute of the action declaration. The articleType defines what content type can be created using the action. An example JSP template that allows the user to fill in some information about the article and create it can be as follows:

<community:user id="user"/>
<html:form action="/content/add">
  <html:hidden property="articleType" value="blog"/>
  <html:hidden property="homeSectionId" value="${user.section.id}"/>
  <html:hidden property="state" value="published"/>
  <html:hidden property="image" value=""/>
  <html:hidden property="articleId"/>

  <html:text property="field(TITLE)" />
  <html:text property="field(BODY)" />

  <html:hidden property="errorUrl" value="error-url" />
  <html:submit value="Create"/>
</html:form>
Form PropertyDescription

articleType

The content type of the article to be created. Note that, if the form property is not present, the content type of the article will be of the configured value of the articleType parameter, configured by the parameter attribute of the action declaration.

homeSectionId

The home section of the article to be created. On an VCE site, it is usually set to the ID of the home section of the requesting user

state

The state of the article to be created. Set it to published if the blogs created by users are to be published on the site by default.

field(field-name)

These are the article fields that you will probably want the user to fill in. For example, a blog may have a title and a body field. The fields are configured in the content type of the publication. So, if a blog needs three fields i.e. "Title", "Sub title" and "Body", the content type needs to declare that and the JSP template can have an entry additional to the example given above. <html:text property="field(SUBTITLE)" />

publicationId

The ID of the publication in which the article is to be created. If not specified, the current publication is used.

successUrl

The URL where the user should be directed to if the article is created successfully. If the form property is not present, the user is directed to the URL of the newly created article.

publishDate

Corresponds to the publish date of the article to be created. The format of the date must be yyyy-MM-dd'T'HH:mm:ss

activateDate

Corresponds to the activation date of the article to be created. The format of the date must be yyyy-MM-dd'T'HH:mm:ss

expireDate

Corresponds to the expiration date of the article to be created. The format of the date must be yyyy-MM-dd'T'HH:mm:ss

errorUrl

The URL where the user should be directed to if any error occurs while trying to creating the blog.

allowSetPublishDate

The property is configured through the parameter attribute of the declared action. It enables the publishDate attribute in the article form.

allowSetActivateDate

The property is configured through the parameter attribute of the declared action. It enables the activateDate attribute in the article form.

allowSetExpireDate

The property is configured through the parameter attribute of the declared action. It enables the expireDate attribute in the article form.