You need to sign in to do that
Don't have an account?
mdinatale
Visualforce variable to class newbie help
I can't seem to get the data from the text box into newpicklistvalue variable in the class to update my data. Please help been trying to do this for a couple days now with no success. It seems like this should work. Thanks in advance.
public with sharing class dynamicpicklist { public ApexPages.StandardController city {get; set;} public dynamicpicklist(ApexPages.StandardController controller) { this.city = controller; } public List<SelectOption> getcitynames() { List<SelectOption> options = new List<SelectOption>(); List<Client_Spouse_Picklist__c> citylist = new List<Client_Spouse_Picklist__c>(); citylist = [Select Account__c, Full_Name__c FROM Client_Spouse_Picklist__c ]; options.add(new SelectOption('--None--','--None--')); for (Integer j=0;j<citylist.size();j++) { options.add(new SelectOption(citylist[j].Full_Name__c,citylist[j].Full_Name__c)); } return options; } public String newpicklistvalue{get; set;} public Pagereference saverec() { State_Fee_limit__c sfl = new State_Fee_limit__c(); sfl.State__c = 'ZZ'; sfl.Fee__c = 2; sfl.Min_Fee__c = 10; sfl.Max_Fee__c = 50; sfl.Note__c = newpicklistvalue; insert sfl; newpicklistvalue=NULL; return NULL; } }
<apex:page standardController="Payment_Info__c" extensions="dynamicpicklist" sidebar="false" > <script language="JavaScript"> function saveit(sl){ document.getElementById("{!$Component.theForm.newval}").value=sl.value; document.getElementById("{!$Component.theForm.saveme}").click(); } </script> <apex:form id="theForm"> <apex:outputlabel value="Name On Check" for="values" /> <apex:selectList value="{!city}" size="1" id="values" onchange="saveit(this);"> <apex:actionSupport event="onchange" reRender="newvalue" /> <apex:selectOptions value="{!citynames}"/> </apex:selectList> display:none;"/> <apex:outputpanel id="newvalue"> <apex:outputpanel > <apex:outputlabel value="New value" for="newval" /> <apex:param name="newpicklist" value="1:123" assignTo="{!newpicklistvalue}" /> <apex:inputText value="{!newpicklistvalue}" id="newval"/> <apex:commandbutton id="saveme" action="{!saverec}" immediate="true" value="Add!" style="visibility:hidden; display:none;"/> </apex:outputpanel> </apex:outputpanel> </apex:form> </apex:page>
I believe this may be your issue:
The var city is a standardcontroller in your class but you are trying to assign it as a selectlist ...
All Answers
Not sure exactly all you are trying to do but start with this, it will at least get the value of the inputtext into the variable then you can go from there:
Extension:
and the page:
Very basic example but it shows what is minimally needed.
The value keeps coming back null, your example didn't work for me, is there some other component im missing? It looks like i have exactly what you have but it just keeps coming back null. Any ideas
When i have immediate="true" on the button it fires the saverec function but doesn't pass the variables, when i take immediate="true" away it passes the variable but doesn't fire the saverec function. Any ideas
My example is meant to do one thing.
You enter a value in the input box, click the button, and the value appears in the outputtext spot.
It works.
The system debug works as well..
What exactly to you implement that it does not work?
What is the value of the variable in each case after clicking the button?
Could it have something to do with having the param assigning a value as well as the inputtext both assigining to the same variable?
Immeidate=true posts without checking any validations.
Possible add an apex:messages /> block to see what error is being given when immediate=true in not present.
thanks for the apex message, if only i new about that 2 weeks ago. i get this message
common.apex.runtime.impl.ExecutionException: Invalid conversion from runtime type
I believe this may be your issue:
The var city is a standardcontroller in your class but you are trying to assign it as a selectlist ...
thanks for all your help, this was the last thing i had to do before we start using salesforce as our primary program.
Good to hear...
Glad to be of help!