Custom „modify content properties dialog“


There is this dialog present in Alfresco (edit-content-properties.jsp), but I wanted to write my own and also describe things I discovered during playing with browseBean.

Let's start with simple bean extending BaseDialogBean with just one getter (and also implementation of abstract methods, ie. getFinishButtonDisabled() or finishImpl()), which returns a Node (org.alfresco.web.bean.repository.Node).

public class ModifyContentProperties extends BaseDialogBean {

    public Node getNode(){
        return this.browseBean.getDocument();

   }
}

Our bean requies just one property – browseBean, so let's set it in faces config:

 <managed-bean>
       <managed-bean-name>ModifyContentProperties</managed-bean-name>
       <managed-bean-class>cz.shmoula.ModifyContentProperties</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       <managed-property>
           <property-name>browseBean</property-name>
           <value>#{BrowseBean}</value>
       </managed-property>
   </managed-bean>

For successfully access to getDocument() method an action listener in web client config is needed. Without this listener (and parameter) the methodreturns null, which is really not expecting value :-). So you need to add that listener and parametr into action definition:

<action id="modify_content_properties">
    <label>Editovat vlastnosti</label>
    <image>/images/icons/edit_form.gif</image>
    <action>dialog:modifyContentProperties</action>
    <action-listener>#{BrowseBean.setupContentAction}</action-listener>
    <params>
        <param name="id">#{actionContext.id}</param>
    </params>
</action>

 A JSP page is very simple, just one component from repo.tld library – propertySheetGrid. More information about this componentcan be found in the alfresco devel wiki. I'm using a (default) externalConfig for describing which property to view or not. Information about config service should be found also in developer wiki, so check it out.

 <%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>
<r:propertySheetGrid id="content-details-contents" value="#{ModifyContentProperties.node}"  externalConfig="true" />

This simple configuration opens a dialog with properties editing inputs, which are filled by information of opened document (or node, if you apply this config – add action – to a Node). BUT you can't save changes. We don't have an OK button method handled. How to get this stuff working? Very simple, Gavinc already wrote this code in org.alfresco.web.bean.content.EditContentPropertiesDialog, so all we need to do is to change a class, which our ModifyContentProperties extending and add overriding methods for default Cancel and OK buttons calls.

 import org.alfresco.web.bean.content.EditContentPropertiesDialog;

public class ModifyContentProperties extends EditContentPropertiesDialog {
    
    @Override
    protected String getDefaultCancelOutcome(){
      return super.getDefaultCancelOutcome() +
                 AlfrescoNavigationHandler.OUTCOME_SEPARATOR +
                 "browse";
    }

    @Override
    protected String getDefaultFinishOutcome(){
       return super.getDefaultFinishOutcome() +
                 AlfrescoNavigationHandler.OUTCOME_SEPARATOR +
                 "browse";
    }

.  .  .

EditContentPropertiesDialog has an editableNode property, which is just a copy of original node, i which we can write our changes. So we need to assign this editableNode to our propertySheetGrid component.

<r:propertySheetGrid id="content-details-contents" value="#{ModifyContentProperties.editableNode}" externalConfig="true"/>

That is all, fast and simple … and now at one place, so you must not spent so much time to looking for how this works as me 🙂


Napsat komentář

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