【问题标题】:Salesforce - commandButton issue when use reRenderSalesforce - 使用重新渲染时的命令按钮问题
【发布时间】:2018-05-06 20:42:45
【问题描述】:

我有一个用于创建案例的 VisualForce,这个 VisualForce 将被嵌入到一个站点上,所以 VisualForce 它是建立在 HTML 之上的,在 HTML 里面我放了以下内容:

<apex:page applyHtmlTag="false" showHeader="false" sidebar="false" docType="" Controller="MyController">
<html>
    <body>
        <!--
            HTML PAGE
        -->
        <div id="FileUpload" class="row">
            <apex:form enctype="multipart/form-data" id="FileUploadForm">
                <apex:pageMessages id="TheMessage" />
                <apex:pageBlock>
                    <apex:pageBlockSection showHeader="false" columns="2" id="block1">
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="File" for="file"/>
                            <apex:inputFile value="{!document.body}" filename="{!strFileName}" id="file"/>
                        </apex:pageBlockSectionItem>
                        <apex:commandButton action="{!cargarArchivo}" value="Cargar Archivo" reRender="TheMessage"/>
                    </apex:pageBlockSection>
                </apex:pageBlock>
            </apex:form>
        </div>
    </body>
</html>
</apex:page>

控制器是:

public String strFileName {get; set;}

public Document document {
    get {
        if (document == null)
            document = new Document();
        return document;
    }
    set;
}

public void cargarArchivo() {
    document.AuthorId = UserInfo.getUserId();
    document.FolderId = '00l29000000L2uH';
    document.name = strFileName;
    document.description = strFileName;
    document.keywords = strFileName;

    try {
        insert document;
    } catch (Exception e) {
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error cargando el archivo, por favor intente nuevamente'));
        return;
    } finally {
        document.body = null; // clears the viewstate
        document = new Document();
    }

    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Archivo cargado con éxito.'));
}

到这里一切都很好,但是当你将 reRender 添加到 commandButton 时,像这样:

<apex:commandButton action="{!cargarArchivo}" value="Cargar Archivo" reRender="TheMessage"/>

我收到以下错误:

3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript:178 
    Uncaught TypeError: actionUrl.indexOf is not a function
        at A4J.Query.getActionUrl (3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript:178)
        at A4J.AJAX.XMLHttpRequest.send (3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript:67)
        at Object.A4J.AJAX.SubmitQuery (3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript:125)
        at Object.A4J.AJAX.Submit (3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript:126)
        at HTMLInputElement.onclick (RF2_CrearCasoWeb_pag?negocio=WEB_GIE:559)

【问题讨论】:

    标签: salesforce visualforce commandbutton rerender


    【解决方案1】:

    您可以使用重新渲染,也可以使用 inputfile 标签。它们不能一起使用,因为错误状态。

    您的页面消息在未提及的情况下自动重新呈现。所以你不用担心。

    作为最佳实践,您可以使用 iframe 标记,它将独立的 HTML 文档嵌入到当前文档中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 2011-06-03
      • 2020-08-06
      • 1970-01-01
      • 2015-02-24
      相关资源
      最近更新 更多