Viewing Task Attachments

This post relates to the custom BPM worklist sample presented in this blog.

In this post, we will look at how to add support for viewing a list of the attachments for a Human Task.

You may recall from the post on creating the domain layer that we created a wrapper to simplify access to the Human Task object.  In that wrapper class, com.oracle.ateam.domain.MTask, we had a property called attachments which is a java.util.List of the attachments.

Attachments are represented by the BPM API class oracle.bpel.services.workflow.task.model.Attachment (see Javadoc here.)

We can add the following code into our view, src/main/webapp/WEB-INF/jsp/taskdetails.jsp, to display information about each attachment.  Here we are displaying three pieces of information about each attachment:

  • ${attachment.updatedBy} is the user who last updated (or created) the attachment,
  • ${attachment.updatedDate.time} is the time the attachment was last updated (or created), and
  • ${attachment.name} is the name of the attachment, most likely this would be the filename, although attachments can also be URLs rather than files.

We also want to display a link to allow the user to download the attachment.  We are making the name into the link.  The link is constructed as follows:


downloadattachment.do?x_tasknumber=${model.task.number}&x_file=${attachment.name}&x_version=${attachment.version}

We are passing the task number, the attachment name and version to a new  downloadattachment controller.  We will see this controller in the next post.

Here is the code we added to the view:


  <h2>Attachments</h2>
  <table width="50%">
    <tr>
      <th class="tl-head" width="150">User</th>
      <th class="tl-head" width="200">Date</th>
      <th class="th-head">Name</th>
    </tr>
  </table>
  <table width="50%">
    <c:forEach items="${model.task.attachments}" var="attachment">
      <tr>
        <td class="tl-row" width="150">${attachment.updatedBy}</td>
        <td class="tl-row" width="200">${attachment.updatedDate.time}</td>
        <td class="tl-row">
          <a href="downloadattachment.do?x_tasknumber=${model.task.number}&x_file=${attachment.name}&x_version=${attachment.version}"
             target="_blank">${attachment.name}</a>
        </td>
      </tr>
    </c:forEach>
  </table>

That’s all we need to view a list of the attachments!  In the next post we will look at how to allow the user to download (open/save) an attachment.

 

About Mark Nelson

Mark Nelson is a Developer Evangelist at Oracle, focusing on microservices and AI. Mark has served as a Section Leader in Stanford's Code in Place program that has introduced tens of thousands of people to the joy of programming, he is a published author, a reviewer and contributor, a content creator and a lifelong learner. He enjoys traveling, meeting people and learning about foods and cultures of the world. Mark has worked at Oracle since 2006 and before that at IBM since 1994.
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a comment