3

I have a commandButton that call two actionfunctions the two actionfunctions call to methods that return a String, but one of the methods some time return null, and when the method return null the visualforce page is reloaded , I try putting a rerender attribute but is not working the visualforce page reload everything when the method return null, the button is "Exportar" this is my code:

<script type="text/javascript">
    function loading(val) {
        //document.getElementById('{!$Component.theForm1.theBlock.theSection.theSectionItemTipo.typeCard}').value;
        if (val) {
            document.getElementById('contentLoading').style.display = 'block';
            document.getElementById('contentLoaded').style.display = 'none';
        } else {
            document.getElementById('contentLoading').style.display = 'none';
            document.getElementById('contentLoaded').style.display = 'block';
        }
    }
</script>
<apex:form id="theForm1">
    <apex:pageBlock title="Reporte Donaciones Recurrentes" id="theBlock">
        <apex:pageMessages id="errors" />

        <apex:actionFunction name="showbn" action="{!chooseCardType}" reRender="theSection,theSectionItemBanco,theSectionItemBlank" status="loading">
            <apex:param name="mediodePago" value="" />
        </apex:actionFunction>
        <apex:actionFunction name="showpn" action="{!showPreNotificacion}" reRender="theSection,theSectionItemBlank" status="loading">
            <apex:param name="nombreBanco" value="" />
        </apex:actionFunction>

        <apex:actionFunction name="generate" action="{!generateURL}" reRender="{!If(cards=='Visa','errors,buttons','')}" status="{!If(cards=='Visa','loading','')}"/>
        <apex:actionFunction name="disable" action="{!runUpdate}" reRender="errors,buttons" status="loading"/>
        <apex:actionFunction name="redirectPre" action="{!redirectPreURL}"/>
        <apex:actionFunction name="enable" action="{!enableExport}" reRender="buttons" status="loading"/>

        <apex:actionStatus id="loading" onstart="loading(true)" onstop="loading(false)" />

        <apex:pageblockSection id="theSection" title="Filtros de búsqueda">
            <apex:pageBlockSectionItem id="theSectionItemMedio" rendered="{!showFinancia}">
                <apex:outputLabel value="Medio de Pago" for="medioCard" />
                <apex:inputField value="{!Donation.Medio_de_Pago__c}" id="medioCard" onchange="showbn(this.value);"/>
            </apex:pageBlockSectionItem>

            <apex:pageBlockSectionItem id="theSectionItemTipo" rendered="{!showFinancia}">
                <apex:outputLabel value="Tipo de Tarjeta" for="typeCard" />
                <apex:selectList id="typeCard" multiselect="false" size="1" value="{!card}" disabled="{!!cardt}">
                    <apex:selectOptions value="{!cards}" />
                </apex:selectList>
            </apex:pageBlockSectionItem>

            <apex:pageBlockSectionItem id="theSectionItemBanco" rendered="{!bank}">
                <apex:outputLabel value="Entidad de Cobro" for="entidadCobro" />
                <apex:selectList id="cobrador" multiselect="false" size="1" value="{!cobra}" onchange="showpn(this.value);">
                    <apex:selectOptions value="{!cobradores}" />
                </apex:selectList>
            </apex:pageBlockSectionItem>

            <apex:pageBlockSectionItem id="theSectionItemBlank" rendered="{!bank}">
                <apex:outputLabel value="Pre Notificación" for="preNotificacion" rendered="{!preNotificacion}"/>
                <apex:inputField value="{!Donation.Pre_Notificado__c}" id="preNotificado" rendered="{!preNotificacion}"/>
            </apex:pageBlockSectionItem>

            <apex:pageBlockSectionItem id="theSectionItemDesde">
                <apex:outputLabel value="Fecha Desde" for="fromDate" />
                <apex:inputField value="{!Donation.npe03__Date_Established__c}" id="fromDate" />
            </apex:pageBlockSectionItem>

            <apex:pageBlockSectionItem id="theSectionItemHasta">
                <apex:outputLabel value="Fecha Hasta" for="toDate" />
                <apex:inputField value="{!DonationHasta.npe03__Date_Established__c}" id="toDate" />
            </apex:pageBlockSectionItem>

            <apex:pageBlockSectionItem id="theSectionItemSemana">
                <apex:outputLabel value="Semana de Cobro" for="weekPay" />
                <apex:selectList id="weekPay" multiselect="true" size="5" value="{!semana}" style="width:50px;">
                    <apex:selectOptions value="{!semanas}" />
                </apex:selectList>
            </apex:pageBlockSectionItem>

            <apex:pageBlockSectionItem id="theSectionItemEstado">
                <apex:outputLabel value="Estado" for="status" />
                <!--  <apex:inputField value="{!npe03__Recurring_Donation__c.npe03__Open_Ended_Status__c}" id="status"/>  -->
                <apex:selectList id="status" multiselect="true" size="3" value="{!estado}">
                    <apex:selectOptions value="{!estados}" />
                </apex:selectList>
            </apex:pageBlockSectionItem>

            <!--  <apex:pageBlockSectionItem id="theSectionItemInStop" >
                <apex:outputLabel value="En pausa" for="inStop"/>
                <apex:inputField value="{!npe03__Recurring_Donation__c.En_Pausa__c}" id="inStop"/> 
            </apex:pageBlockSectionItem> -->
        </apex:pageblockSection>
        <div id="contentLoaded">
            <apex:pageblockSection id="buttons">
                <apex:pageBlockSectionItem >
                    <apex:commandButton value="Buscar" action="{!runSearch}" reRender="grilla,debug,errors,buttons" status="loading"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:commandButton value="Pre Visualizar" onclick="redirectPre();" oncomplete="enable();" disabled="{!!exportedPre}" />
                    <apex:commandButton value="Exportar" onclick="generate();" oncomplete="disable();" disabled="{!!exported}" />                     
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </div>
        <div id="contentLoading" style="display: none;">
            <div style="text-align: center;">
                <img src="/img/loading.gif" alt="Procesando..." />
            </div>
        </div>
        <br/>
        <apex:pageblockSection id="grilla" columns="1">
            <apex:pageBlockTable value="{!resultado}" var="c">
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Id Donación" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Id" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Id}" />
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="PSN" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="PSN__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.PSN__c}" />
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Nombre Cuenta" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="AccountId" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Nombre_Cuenta__c}" />
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Nombre" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Nombre__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Nombre__c}" />
                </apex:column>                  
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Apellido" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Apellidos__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Apellidos__c}" />
                </apex:column>                  
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="DNI" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="N_mero_de_Documento__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.N_mero_de_Documento__c}" rendered="{!c.N_mero_de_Documento__c!=null}"/>
                    <apex:outputField value="{!c.Account.N_Fiscal__c}" rendered="{!c.N_mero_de_Documento__c==null}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Monto" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Amount" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Amount}" />
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Tipo Tarjeta" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Tipo_de_Tarjeta__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Tipo_de_Tarjeta__c}" />
                </apex:column>                  
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Número Tarjeta" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Numero_de_Tarjeta__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Numero_de_Tarjeta__c}" />
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Fecha Vencimiento" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Fecha_de_Vencimiento__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Fecha_de_Vencimiento__c}" />
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Número Cuenta" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Numero_de_Tarjeta__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Numero_de_Cuenta__c}" />
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="Frecuencia" action="{!toggleSort}" rerender="grilla,debug">
                            <apex:param name="sortField" value="Frecuencia__c" assignTo="{!sortField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!c.Frecuencia__c}" />
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageblockSection>
        <apex:pageMessages />
    </apex:pageBlock>
</apex:form>

2
  • If the card is NOT visa "it should reload" – Ashwani Jan 19 '17 at 19:08
  • yes that's right – Angello Camacho Jan 19 '17 at 19:12
1

Try below solution:

Command button
Added return to prevent commandbutton default action.

<apex:pageBlockSectionItem >
   <apex:commandButton value="Pre Visualizar" onclick="redirectPre(); return false;" oncomplete="enable();" disabled="{!!exportedPre}" />
   <apex:commandButton value="Exportar" onclick="generate(); return false;" oncomplete="disable();" disabled="{!!exported}" />                     
</apex:pageBlockSectionItem>

Action function:
Added fakeID so page don't reload. Updated:

<apex:actionFunction name="generate" rendered="{!cards=='Visa'}" action="{!generateURL}" reRender="errors,buttons" status="loading"/>
<apex:actionFunction name="generate" rendered="{!cards!='Visa'}" action="{!generateURL}" reRender="fakeID" status=""/>
7
  • I tried it, but this not working, I think the condicional isn't working because instead of fakeID I put erros,buttons, and doesn't redirect, but can't see the error in the conditional, can you? – Angello Camacho Jan 19 '17 at 19:48
  • try changing actionfunctin to <apex:actionFunction name="generate" action="{!generateURL}" reRender="errors,buttons" status="{!If(cards=='Visa','loading','')}"/> @AngelloCamacho – Ashwani Jan 19 '17 at 20:17
  • ok but only need to rerender when the cards equals to Visa – Angello Camacho Jan 19 '17 at 20:18
  • @AngelloCamacho My doubt is there is issue with IF. If this works we can workaround the solution – Ashwani Jan 19 '17 at 20:19
  • I changed it and doesn't redirect but the status is not showing. – Angello Camacho Jan 19 '17 at 20:23
0

I created another actionfuction that rerender another tags and I created a javascript function that is called from the commandbutton this function obtain the credit card and call to the corresponding actionfunction.

1
  • 2
    Is this post meant to be an answer? Or did you intend to edit your question? It's hard to tell. – Adrian Larson Jan 19 '17 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.