You need to sign in to do that
Don't have an account?

Passing a Visualforce picklist value input to an APEX variable
Hi guys,
I have a Visualforce table that I'd like to dynamically filter through a VF picklist. The filter is a string, which is "Currency". So by default it is on USD and will show all records that are in USD, but I'd like to pick 'CAD' from a dropdown on the page and it will rerender the table with only CAD records.
I have borrowed some code from this discussion, but the button is so far unresponsive and doesn't rerender. I've attached my code below with only the relevant parts:
VISUALFORCE CODE
CONTROLLER
I think what I'm trying to do is Click "Go", it passes the selected value to the "getCurrency" method, which initializes a string value for the currency in Apex so I can bind it in the SOQL query. Then the getCurrency method will run the main method again to re-render the page.
It looks like there's a few bumps I can't seem to figure out, and I've been racking my brains on this for ages!
Thanks in advance!
I have a Visualforce table that I'd like to dynamically filter through a VF picklist. The filter is a string, which is "Currency". So by default it is on USD and will show all records that are in USD, but I'd like to pick 'CAD' from a dropdown on the page and it will rerender the table with only CAD records.
I have borrowed some code from this discussion, but the button is so far unresponsive and doesn't rerender. I've attached my code below with only the relevant parts:
VISUALFORCE CODE
<apex:page controller="InvoicesReadyToPayV4"> <apex:form> <apex:pageBlock title="Test Report"> <apex:pageBlockSection columns="1"> Select Currency: <apex:selectList size="1" value="{!currencyPickvalue}"> <apex:commandButton value="Go" action="{!getCurrency}" reRender="table1"/> <apex:selectOption itemLabel="USD" itemValue="USD"></apex:selectOption> <apex:selectOption itemLabel="CAD" itemValue="CAD"></apex:selectOption> <apex:selectOption itemLabel="AUD" itemValue="AUD"></apex:selectOption> </apex:selectList> </apex:pageBlockSection> <!-- More code to create tables --> </apex:pageBlock> </apex:form> </apex:page>
CONTROLLER
public class InvoicesReadyToPayV4 { public List<GEOinvoice__c> geoInvoices {get;set;} public List<Account> localPartners {get;set;} public Set<Id> localPartnerIds = new Set<Id>(); public Map<Account, Decimal> LocalPartnerSum {get;set;} public Map<Account, String> LocalPartnerReady {get;set;} public String currencyPickvalue {get;set;} public String selectedCurrency {get;set;} //selectedCurrency = 'USD'; //Default public void getCurrency() { selectedCurrency = currencyPickvalue; System.debug('Selected Currency: ' + selectedCurrency); //Do I have to re-run the below method? } //Find all invoices to be shown in report public InvoicesReadyToPayV4() { geoInvoices = [SELECT Id, Name FROM GEOInvoice__c WHERE LP_invoice_currency__c = :selectedCurrency]; //More code related to the tables } }
I think what I'm trying to do is Click "Go", it passes the selected value to the "getCurrency" method, which initializes a string value for the currency in Apex so I can bind it in the SOQL query. Then the getCurrency method will run the main method again to re-render the page.
It looks like there's a few bumps I can't seem to figure out, and I've been racking my brains on this for ages!
Thanks in advance!
Your code works fine.
rerender => id of the part of the form.
<apex:commandButton value="Go" reRender="Render" action="{!CurrencyGenerate}"/>
<apex:outputPanel id="Render">
What is your problem currently?
All Answers
As you know, that was not a button but: <apex:actionSupport event="onchange" action="{!getleads}" rerender="table1"/>
It was an action support for the <apex:selectList> but for a button, it is different.
Your <apex:commandButton value="Go"> should be outside <apex:selectList> like the solution here:
https://salesforce.stackexchange.com/questions/23718/rerender-based-on-selectoption-value-on-commandbutton-click
I have moved the button outside the List and it points to a PageReference. I have also moved the list to Apex as they did in your example.
However I'm still having issues passing in the selected option into Apex. I think it is the commandButton not actually putting it in apex. I'm wondering how I can pass the selected value into the InvoicesReadyToPayV4() method so it can run the SOQL query using the new "currencyPickvalue".
VF
Apex
Your code works fine.
rerender => id of the part of the form.
<apex:commandButton value="Go" reRender="Render" action="{!CurrencyGenerate}"/>
<apex:outputPanel id="Render">
What is your problem currently?
Thank you very much for your patience, it works now!
I was having trouble rerendering the page, so I removed reRender and it worked fine, although it reloaded the page every time. Then I tried putting the id = "Render" in the <apex:form id="Render">, and it reRendered the whole page on change. That's exactly what I needed.
Also, to get my code working I had to make my method void to call it from the commandButton.
Thanks!