+ Start a Discussion
Shavi DabgotraShavi Dabgotra 

display the field from custom object, To be display in Visualforce using Custom controller.

Hi Everyone,
I want to display the field from my custom object(Timesheet__c), To be display in Visualforce using Custom controller. 

Below is my VF: 
<apex:page controller="ManagementTime" lightningStylesheets="true" >
    <apex:form >
        <apex:pageBlock >
           <apex:pageblockSection columns="1" >
               <apex:pageblockTable value="{!objlist}"  var="c" >
                   <apex:column headervalue="Task"  >
                      <apex:inputField value="{!c.Task_Type__c}"/>
                       <apex:outputField value="{!c.Task_Type__c}" /> 
                   </apex:column> 
                   <apex:column headervalue="Monday" rendered="true" >
                      <apex:inputField value="{!c.Monday__c}"/>
                       <apex:outputField value="{!c.Monday__c}" /> 
                   </apex:column> 

               </apex:pageBlockTable>
            </apex:pageblockSection>     
        </apex:pageBlock>
    </apex:form>
</apex:page>

Below is my Custom controller: 

public class ManagementTime{
    public list<Timesheet__c> objlist {get;set;}
    public ManagementTime(){
        objlist = [SELECT Id, Task_Type__c FROM Timesheet__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }
}

But I my getting only header name:

User-added image


But I want like this: 

User-added image

Could someone help me in this? I am new to visualforce development.Thank you in advance!

Vishwajeet kumarVishwajeet kumar
Hello,
Try below :
 <apex:page controller="ManagementTime" lightningStylesheets="true" >
    <apex:form >
        <apex:pageBlock >
           <apex:pageblockSection columns="1" >
               <apex:pageblockTable value="{!objlist}"  var="c" >
                   <apex:column headervalue="Task">
                      <apex:inputField value="{!c.Task_Type__c}"/>                       
                   </apex:column> 
                   <apex:column headervalue="Monday">
                      <apex:inputField value="{!c.Monday__c}"/>                      
                   </apex:column> 
               </apex:pageBlockTable>
            </apex:pageblockSection>     
        </apex:pageBlock>
    </apex:form>
</apex:page>


Thanks.
Shavi DabgotraShavi Dabgotra

Hi Vishwajeet,
This is also not working. It is working as same before. 

Please help me in this!

Malika Pathak 9Malika Pathak 9

Hi Shavi Dabgotra,

please find the solution

 

<apex:page controller="ManagementTime" lightningStylesheets="true" >
<apex:form >
<apex:pageBlock >
<apex:pageblockSection columns="1" >
<apex:pageblockTable value="{!objlist}" var="c">
<apex:column headervalue="Task" >
<apex:inputField value="{!c.Task_Type__c}"/>
<apex:outputField value="{!c.Task_Type__c}" />
</apex:column>
<apex:column headervalue="Monday" rendered="true" >
<apex:inputField value="{!c.Monday__c}"/>
<apex:outputField value="{!c.Monday__c}" />
</apex:column>
</apex:pageblockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

public class ManagementTime{
public list<Timesheet__c> objlist {get;set;}
public ManagementTime(){
objlist = [SELECT Id, Task_Type__c,Monday__c FROM Timesheet__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
}

 

User-added image

 

If you find this solution is helpful for you please mark the best answer

Shavi DabgotraShavi Dabgotra

Hi Malika Pathak,

I have tried your sample code as well. But it is displaying the same. Could you help me in this? 
Thank you!

Vishwajeet kumarVishwajeet kumar
Hello,
Below works for me. i see that one of the field - "Monday__c" is not queried in controller method, may be that's the issue.

 <apex:page controller="ManagementTime" lightningStylesheets="true" >
    <apex:form >
        <apex:pageBlock >
           <apex:pageblockSection columns="1" >
               <apex:pageblockTable value="{!objlist}"  var="c" >
                   <apex:column headervalue="Task">
                      <apex:inputField value="{!c.Task_Type__c}"/>                       
                   </apex:column> 
                   <apex:column headervalue="Monday">
                      <apex:inputField value="{!c.Monday__c}"/>                      
                   </apex:column> 
               </apex:pageBlockTable>
            </apex:pageblockSection>     
        </apex:pageBlock>
    </apex:form>
</apex:page>
Shavi DabgotraShavi Dabgotra

Hi Vishwajeet, 
That is working when we provide Id in the URL. But I want the empty feilds when we load the VF page. Can you help me in this? Thank you!