Web Tools
This BLOBWorkitemController is used to store large objects into a single ItemCollection mapped to a EntityBean. The BlobWorkitem is always bounded to a parent workitem by its referrer id ($uniqueidRef). So an application can implement a lazy loading for BLOBWorkitems. The read- and write access settings of BLOBWorkitems are always synchronized to the settings of the parent workitem. Before the BlobWorkitem can be accessed the workitem needs to be loaded by the load() method. The Data can be accessed by the embedded Itemcollection through the method getWorkitem(). The BlobWorkitem can be saved by calling the save() method. Both - the load() and the save() method expect the Parent ItemCollection where the BlobWorkitem should be bound. This will be shown now in an example:
The LOBWorkitemController can be used easily as a backing bean defined in the facesContext.xml file:
.....
<managed-bean>
<managed-bean-name>workitemBlobMB</managed-bean-name>
<managed-bean-class>org.imixs.workflow.jee.jsf.util.BLOBWorkitemController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
.....
The BLOBWorkitemMB can be used exactly the same way as the SimpleWorkflowController. To access a item the following code example can be used.
<h:inputText required="true"
value="#{workitemBlobMB.item['txtLargeDataField']}" id="blob_data_id">
</h:inputText>
The next code example shows a WorkitemController (extended by the AbstractWorkflowControler) which overwrites the doProcess() method to save some large data into an separate Blobworkitem using the BLOBWorkitemController:
public void doProcessWorkitem(ActionEvent event) throws Exception {
// do default processing
super.doProcessWorkitem(event);
// get the BLOBWorkitemController from the FacesContext
workitemBlobMB = (BLOBWorkitemController) FacesContext
.getCurrentInstance().getApplication().getELResolver()
.getValue(FacesContext.getCurrentInstance().getELContext(),
null, "workitemBlobMB");
// load/create new LOBworkitem
workitemBlobMB.load(workitemItemCollection);
// now add additional Large data into the blob bean
workitemBlobMB.getWorkitem().replaceItemValue("lobDataField", myLargeDataObject);
workitemBlobMB.save(workitemItemCollection);
}
You can also use the BLOBWorkitemController to add file attachments to the BLOBWorkitem. This can be done for example also during the doProcesWorkitem() method of the main Workitem
.....
workitemBlobMB.addFile(item.getData(), item.getFileName(),
item.getContentType());
File attachments will be stored into the property $file. The property value holds a hashMap with the filename, content type and byte array data.
The following example shows how to add a RichFaces Upload Control element using the LOBWorkitemControler. Files will be saved into the LOBWorkitem. The richFaces FileUpload widget can be used together with the Imixs BLOBWorkitemController in a jsf page:
<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
listHeight="100px"
maxFilesQuantity="#{fileUploadBean.uploadsAvailable}" id="upload"
immediateUpload="#{fileUploadBean.autoUpload}"
acceptedTypes="jpg, gif, png, bmp"
allowFlash="#{fileUploadBean.useFlash}">
<a4j:support event="onuploadcomplete" reRender="attachment_info_id" />
</rich:fileUpload>
....
......
<a4j:outputPanel id="attachment_info_id" style="float: left; min-width: 120px;">
<rich:dataList id="attachmentlist_id" var="attachment"
value="#{workitemBlobMB.files}" >
<h:outputText escape="false" value="<a target='_balnk' href='" />
<h:outputText escape="false"
value="#{facesContext.externalContext.requestContextPath}/RestService/workflow/#{workitemBlobMB.item['$uniqueID']}/#{attachment}" />
<h:outputText escape="false" value="'>#{attachment}</a>" />
<h:outputText value=" " style="margin-left:10px;" />
</rich:dataList>
</a4j:outputPanel>
The jsf example makes use of the Imixs REST Service interface to support a download link for each attachment.
This is the backing bean code example to add a file during the listener event. The details about the RichFaces Upload Widget on the RichFaces Home Page.
....
public void listener(UploadEvent event) throws Exception {
UploadItem item = event.getUploadItem();
this.getWorkitemBlobBean().load(workitemItemCollection);
this.getWorkitemBlobBean().addFile(item.getData(), item.getFileName(),
item.getContentType());
uploadsAvailable--;
}
....