-1

I have a VF page that displays a table of records. I'd like the table to be filtered by one of it's String fields, "currency", so if I chose 'USD', it will only show records with 'USD', same for 'CAD', etc.

I think the way to do it is choose the currency from a picklist, then it passes the String to the Controller, where it will SOQL the records using the updated bind variable, then rerenders the page.

It seems I'm having trouble with passing in the field to the apex method where the SOQL is.

VF

<apex:page controller="InvoicesReadyToPayV4" tabStyle="GEOinvoice__c">
  <apex:form >
    <apex:pageBlock title="Test GEO Invoice Report">
        <apex:pageBlockSection columns="1">
            Select Currency:
            <apex:selectList value="{!currencyPickvalue}" size="1">
                <apex:selectOptions value="{!CurrencyValue}"/>
            </apex:selectList>
            <apex:commandButton value="Go" reRender="Render" action="{!CurrencyGenerate}"/>
        </apex:pageBlockSection>

                <!-- Other code to create tables -->

   </apex:pageBlock>
</apex:form>

Controller

public class InvoicesReadyToPayV4 {
    public List<GEOinvoice__c> geoInvoices {get;set;}

    public String currencyPickvalue {get;set;}

    public List<SelectOption> getCurrencyValue() {
        List<SelectOption> CurrencyOptions = new List<SelectOption>();
        CurrencyOptions.add(new SelectOption('USD', 'USD'));
        CurrencyOptions.add(new SelectOption('CAD', 'CAD'));
        CurrencyOptions.add(new SelectOption('AUD', 'AUD'));
        CurrencyOptions.add(new SelectOption('EUR', 'EUR'));
        return CurrencyOptions;
    }

    public PageReference CurrencyGenerate() {
        ApexPages.StandardController sc = new ApexPages.StandardController();
        System.debug('Page Refreshed.');
        return null;
    }

    public InvoicesReadyToPayV4() {
        currencyPickvalue = 'USD';

        //Find all invoices in that would show up in the report.
        geoInvoices = [SELECT Id, Name
                         FROM GEOInvoice__c
                          AND LP_invoice_currency__c = :currencyPickvalue];

                     /* Rest of code */
    }
}

I think I'm stuck on what should be in the action={!xxx} attribute of the button, as I'm unsure how to call the InvoicesReadyToPayV4 method properly.

I've looked at the following resources yet am still racking my brain. Get value for apex class from visualforce page Pass Field Api From Visualforce Page to Controller https://developer.salesforce.com/forums/?id=906F0000000fzeOIAQ

Thanks!

  • Your form needs id= "Rerender" cause thats the id you are referencing in your rerender attribute. I would btw change it to theForm or something similar. – Basti Oct 14 '17 at 8:22
  • Your Action to Call would be action={!InvoicesReadyToPayV4} " – Basti Oct 14 '17 at 8:25
  • A couple other things seem odd. But this will make you get further... :) – Basti Oct 14 '17 at 8:26
  • Thanks! I have put the rerender into the form field and it worked. – PrawnCrackers Oct 17 '17 at 4:59
0

Your reRender attribute needs to target something, so you'll need to give some containing element an ID:

<apex:form id="myForm">
    <apex:pageBlock title="Test GEO Invoice Report">
        <apex:pageBlockSection columns="1">
            Select Currency:
            <apex:selectList value="{!currencyPickvalue}" size="1">
                <apex:selectOptions value="{!CurrencyValue}"/>
            </apex:selectList>
            <apex:commandButton value="Go" reRender="myForm" action="{!CurrencyGenerate}"/>
        </apex:pageBlockSection>

                <!-- Other code to create tables -->

   </apex:pageBlock>
</apex:form>

Note that any elements inside your containing element will be re-rendered, but not the containing element itself. In your case, you may not really need to target a specific part of the page to re-render, so you could just leave the attribute off altogether:

<apex:form >
    <apex:pageBlock title="Test GEO Invoice Report">
        <apex:pageBlockSection columns="1">
            Select Currency:
            <apex:selectList value="{!currencyPickvalue}" size="1">
                <apex:selectOptions value="{!CurrencyValue}"/>
            </apex:selectList>
            <apex:commandButton value="Go" action="{!CurrencyGenerate}"/>
        </apex:pageBlockSection>

                <!-- Other code to create tables -->

   </apex:pageBlock>
</apex:form>

This will re-render the whole page.

  • Yes, thank you. I thought it was something wrong with my Apex calls but I had just put render in the wrong tag. – PrawnCrackers Oct 17 '17 at 5:00

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.