You need to sign in to do that
Don't have an account?
Code+1
pass inputfield value from visualforce page to apex controller
Hello All,
I am trying to pass the Input field value from Visualforce page to apex controller class.
Please let me know how to capture the value.
Below is the code.
<apex:page standardController="Activity_Tracker__c" extensions="dependentPicklistController">
<apex:messages style="color:red"></apex:messages>
<apex:form >
<apex:pageblock >
<apex:pageblockSection >
<apex:inputField value="{!Activity_Tracker__c.Category__c}" />
<apex:inputField value="{!Activity_Tracker__c.Sub_Customers__c}" />
</apex:pageblockSection>
</apex:pageblock>
<apex:commandButton action="{!search}" value="search"/>
<apex:pageBlock >
<apex:pageBlockTable value="{!records}" var="item">
<apex:column value="{!item.Category__c}"/>
<apex:column value="{!item.Sub_Customers__c}"/>
<apex:column value="{!item.Status__c }"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller --
public with sharing class dependentPicklistController{
public List<Activity_Tracker__c> records{get;set;}
public Activity_Tracker__c Category__c{get; set;}
public pagereference search()
{
records=[Select ID, Category__c, Sub_Customers__c, Status__c From Activity_Tracker__c ];
system.debug('11111' +Query);
return null;
}
}
In this I am trying to capture Category__c, Sub_Customers__c (Dependent Picklists) in the Apex Class.
Thanks...
I am trying to pass the Input field value from Visualforce page to apex controller class.
Please let me know how to capture the value.
Below is the code.
<apex:page standardController="Activity_Tracker__c" extensions="dependentPicklistController">
<apex:messages style="color:red"></apex:messages>
<apex:form >
<apex:pageblock >
<apex:pageblockSection >
<apex:inputField value="{!Activity_Tracker__c.Category__c}" />
<apex:inputField value="{!Activity_Tracker__c.Sub_Customers__c}" />
</apex:pageblockSection>
</apex:pageblock>
<apex:commandButton action="{!search}" value="search"/>
<apex:pageBlock >
<apex:pageBlockTable value="{!records}" var="item">
<apex:column value="{!item.Category__c}"/>
<apex:column value="{!item.Sub_Customers__c}"/>
<apex:column value="{!item.Status__c }"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller --
public with sharing class dependentPicklistController{
public List<Activity_Tracker__c> records{get;set;}
public Activity_Tracker__c Category__c{get; set;}
public pagereference search()
{
records=[Select ID, Category__c, Sub_Customers__c, Status__c From Activity_Tracker__c ];
system.debug('11111' +Query);
return null;
}
}
In this I am trying to capture Category__c, Sub_Customers__c (Dependent Picklists) in the Apex Class.
Thanks...
Though i would recomend renaming that variable, having it with the same name as a custome field could be confusing.
Controler:
public Activity_Tracker__c tracker{get; set;}
VF page:
<apex:inputField value="{!tracker.Category__c}" />
<apex:inputField value="{!tracker{.Sub_Customers__c}" />
All Answers
Though i would recomend renaming that variable, having it with the same name as a custome field could be confusing.
Controler:
public Activity_Tracker__c tracker{get; set;}
VF page:
<apex:inputField value="{!tracker.Category__c}" />
<apex:inputField value="{!tracker{.Sub_Customers__c}" />
Hi Krishna,
As your page has standrad controller you should have one argument constructor . From the standradController you can get the record and related field value .
Check links it will help you .
https://www.salesforce.com/docs/developer/pages/Content/apex_pages_standardcontroller.htm
Please let me know if you need any further help .
Yes, The functionality worked fine as expected .Thanks..
Thanks Manoj for Sharing..
I was using this very same approach where I instantiated by object in the controller and tried to reference the same using !testObj.Object_Name__c, where Object_Name__c is my custom picklist field.
However, on selection of a value 'Account' from that picklist field, my rerender request should take me to a different pageblocksection. Someway that does not seem to be working.
Can you tell me where I am going wrong. Without doing a instantion in the controller, the re-renedered functionality is working fine. (When I am using TestA__c.Object_Name__c=='Account')
Below is my code:
<apex:inputField value="{!testObj.Object_Name__c}">
<apex:actionSupport event="onchange" reRender="ajaxrequest" />
</apex:inputfield>
<!-- </apex:actionRegion>-->
</apex:PageBlockSectionItem>
</apex:PageBlockSection>
<apex:outputPanel id="ajaxrequest">
<apex:pageBlockSection rendered="{!testObj.Object_Name__c=='Account'}">
<apex:pageBlock title="Enter Account Details" id="AccountInsert">
<apex:pageblockSection >
Opened up an old thread. Any help would be a huge help.