Delete dialog workaround


Write this one, or not to write this blogpost? That is the question :-). But I would like to simply remember for some things i did, so let's do it! In my DMS I have some multimedia content saved and this content has attached description in xml file. Also I have my own space view (more info here), so I show just that multimedia content. In case of deletion that content I want to delete that xml too, so how to do that?

First we need to create an action (it's just a copy of original action ;-)) specification in web-client-config and name it – in my case "delete_doc_shm":

<action id="delete_doc_shm">
    <permissions>
        <permission allow="true">Delete</permission>
    </permissions>
    <evaluator>org.alfresco.web.action.evaluator.DeleteDocEvaluator</evaluator>
    <label-id>delete</label-id>
    <image>/images/icons/delete.gif</image>
    <action-listener>#{BrowseSessionBean.deleteFile}</action-listener>
    <params>
        <param name="id">#{actionContext.id}</param>
        <param name="ref">#{actionContext.nodeRef}</param>
    </params>
</action>

It's pretty simple, just a definition of action with Evaluator and wanted permissions. I wrote a blogpost about this a year about :-). Now I have an action, so I need to add it into some group, or view link directly. Action groups are defined in web-client-config too:

<action-group id="session_browse">
    <show-link>false</show-link>
    <style-class>inlineAction</style-class>
    .  .  .
     <action idref="delete_doc_shm" />
</action-group>

And view of this group is realised by actions component (r variable is variable defined by richListComponent, library prefix r is Alfresco's repo taglib):

.  .  .
<r:actions id="actions_menu_1" value="session_browse" context="#{r}" showLink="false" styleClass="inlineAction" />
.  .  .  

The result's like this (there's no difference in original view of that actions menu and this, but functionality – see below ;-)):

Image and video hosting by TinyPic

Now some application logic: In case of pressing our delete butto, BrowseSessionBean.deleteFile() method is called. This method just do same things that original BrowseBean.deleteFile() does, but redirects to my own dialog:

public void deleteFile(ActionEvent event) {
    .  .  .  some foo – bar stuff  .  .  .
    FacesContext fc = FacesContext.getCurrentInstance();
    NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
    navigationHandler.handleNavigation(fc, null, "dialog:deleteVcfFile");
}

This dialog is defined in web-client-config like

<dialog
    name="deleteVcfFile"
    page="/jsp/dialog/delete.jsp"
    managed-bean="DeleteVcfContentDialog"
    icon="/images/icons/delete_large.gif"
    title-id="delete_file"
    description-id="delete_file_info" />

and points to DeleteVcfContentDialog bean:

<managed-bean>
    <description>The bean that backs up the Delete Content Dialog</description>
    <managed-bean-name>DeleteVcfContentDialog</managed-bean-name>
    <managed-bean-class>cz.shmoula.dialog.DeleteVcfContentDialog</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>navigator</property-name>
        <value>#{NavigationBean}</value>
    </managed-property>
    .  .  .  more properties  .  .  .
</managed-bean>

Class managing this bean extends DeleteContentDialog and has only one method – finishImpl. See following source, it's commented:

public class DeleteVcfContentDialog extends org.alfresco.web.bean.content.DeleteContentDialog {

    @Override
    protected String finishImpl(FacesContext context, String outcome)throws Exception {
        // get the content to delete
        VcfNode node = new VcfNode(this.browseBean.getDocument());
        if (node != null) {
            if (ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(node.getType())) {
                // delete the mlContainer and its translations
                getMultilingualContentService().deleteTranslationContainer(node.getNodeRef());
            } else {
                // getting attached xml node
                Node descriptionXml = node.getXmlNode();
                // and if xml exists, delete it!
                if(descriptionXml != null)
                    this.getNodeService().deleteNode(descriptionXml.getNodeRef());
                
                // delete the node
                this.getNodeService().deleteNode(node.getNodeRef());
            }
        }
        return outcome;
    }
}

As I can see, it'll be much better to implement some transactions inside this method to 'do some atomicity' 8-). VcfNode is my Node extension, I'll try to describe it in next blogpost.

So, it's pretty easy to workaround system dialogs thanks to Alfresco source code. But sometimes you can find things, which looks like there is no source in sdk 🙁 but google always helps!


Napsat komentář

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *