Auto-save doc after delete of attachment in File D

2019-01-29 09:39发布

问题:

I am allowing deletion of attachments in the File Download control. If a user deletes an attachment and navigates away from the page (without saving), the attachment does not actually get removed.

There is an onclick event for the control, but it isn't specific to deletion. Is there a way to automatically call a .save() after deletion of an attachment?

回答1:

Here is a SSJS snippet which allows to add an action to the delete function of a FileDownload control.

<xp:this.beforeRenderResponse>
    <![CDATA[#{javascript:

    /***
     * adds an additional method to "delete action"
     * of a UIFileDownload control
     *  
     * @param UIFileDownload component
     * @author Sven Hasselbach
     * @category SSJS
     * @category UI
     * @version 0.3
     */
    function overrideFileDownloadAction( fDownload ){
        if( fDownload === null )
            return;
        rekOverrideFileDownloadAction( fDownload, fDownload );
    }

    function rekOverrideFileDownloadAction( component:javax.faces.component.UIOutput, fDownload:com.ibm.xsp.component.UIFileDownload  ){
        try{
            var children:java.util.List = component.getChildren();
            var it:java.util.Iterator = children.iterator();
            var curChild:javax.faces.component.UIOutput;

            while( it.hasNext() ){
                curChild = it.next();
                if( typeof( curChild ) === 'com.ibm.xsp.component.xp.XspEventHandler' ){

                    var group = new com.ibm.xsp.actions.ActionGroup();
                    var list = new java.util.ArrayList();
                    group.setComponent( fDownload );
                    list.add( curChild.getAction() );
                    list.add( mBinding );
                    group.setActions( list );
                    curChild.setAction(group);
                }
                rekOverrideFileDownloadAction( curChild , fDownload );
            }
        }catch(e){}    
    }

    var mBinding = facesContext.getApplication().createMethodBinding("#{javascript:document1.save()}", null );
    overrideFileDownloadAction( getComponent( 'fileDownload1' ) );
    }]]>
</xp:this.beforeRenderResponse>

You have to change the code in the MethodBinding mBinding and the name of the FileDownLoad control. Please keep in mind that this code will only save the document if there are no validation problems. To disable required fields you have to add the following line of code curChild.setDisableValidators( true ); in the if block.



回答2:

An alternative is to use the enableModifiedFlag property to ensure that the user is prompted if leaving the page without saving.

More details at http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.ui.doc/wpd_controls_pref_enablemodifiedflag.html