salesforce - How to get an input value on a Visualforce page from an Apex controller? -
let's pretend have sobject called mycutomobject fields column1, column2, column3, pickmecolumn , others. type of pickmecolumn picklist.
while it's easy access object's instance data in page, i'm bit stucked how user's input data page accessible inside controller.
page code:
<apex:page sidebar="false" standardcontroller="mycustomobject__c" extensions="mycustomsearchcontroller"> <apex:form > <apex:pageblock title="search criteria"> <apex:pageblocksection> <apex:inputfield value="{!myobject.pickmecolumn__c}" /> </apex:pageblocksection> <apex:commandbutton value="search" id="searchbutton" action="{!search}"/> </apex:pageblock> <apex:pageblock title="search results"> <apex:pageblocktable value="{!myobjectlist}" var="myobject"> <apex:repeat value="{!myobject}" var="arecord"> <apex:column value="{!arecord.column1__c}"/> <apex:column value="{!arecord.column2__c}"/> <apex:column value="{!arecord.column3__c}"/> </apex:repeat> </apex:pageblocktable> </apex:pageblock> </apex:form> </apex:page>
controller code:
public class mycustomsearchcontroller { public mycutomobject__c myobject {get;set;} public list<mycutomobject__c> myobjectlist {get;set;} public mycustomsearchcontroller(apexpages.standardcontroller controller) { } public pagereference search() { string valueselectedbyuser = '??? help!'; myobjectlist = [select column1__c, column2__c, column3__c mycutomobject__c pickmecolumn__c = valueselectedbyuser]; return apexpages.currentpage(); } }
in controller's code so:
public class mycustomsearchcontroller { public mycutomobject__c myobject {get;set;} public list<mycutomobject__c> myobjectlist {get;set;} public mycustomsearchcontroller(apexpages.standardcontroller controller) { myobject = new mycustomobject__c(); // must create object! } public pagereference search() { string valueselectedbyuser = myobject.pickmecolumn__c; myobjectlist = [select column1__c, column2__c, column3__c mycutomobject__c pickmecolumn__c = :valueselectedbyuser]; // have add colon return apexpages.currentpage(); } }
Comments
Post a Comment