删除文件下载控件中的附件后自动保存文档? [英] Auto-save doc after delete of attachment in File Download control?

查看:26
本文介绍了删除文件下载控件中的附件后自动保存文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许删除文件下载控件中的附件.如果用户删除附件并离开页面(未保存),则该附件实际上并未被删除.

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.

该控件有一个 onclick 事件,但它不是特定于删除的.有没有办法在删除附件后自动调用 .save() ?

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?

推荐答案

这是一个 SSJS 代码段,它允许向 FileDownload 控件的删除功能添加操作.

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>

您必须更改 MethodBinding mBinding 中的代码和 FileDownLoad 控件的名称.请记住,如果没有验证问题,此代码只会保存文档.要禁用必填字段,您必须在 if 块中添加以下代码行 curChild.setDisableValidators( true );.

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.

这篇关于删除文件下载控件中的附件后自动保存文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆