function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PrazPraz 

How to autopopulate the data in VF page

I have made a VF page having some textboxes and buttons. On clicking Get Details button it should come back to the same page with textboxes auto-populated with data.

 

I have done the following things still it is not auto-populating the page. Please help me in this regard

 

in VF page

 

<apex:outputPanel style="width:100px;">
                <apex:inputText value="{!data1}" id="id3" style="width:100px;" />
            </apex:outputPanel>

 

 

in Apex class

 

 

PageReference pageRef = Apexpages.currentPage();

 

String hi = '0.00';
           
 pageRef.getParameters().put('data1', hi);

 

return pageRef;

 


the datatype of data1 is decimal

 

Please tell me how can I approach

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
visualforce_devvisualforce_dev

This code is working for me

 

<apex:OutputPanel style="width:100px;"> <apex:inputText value="{!dateOfEntry}" id="id1" style="width:100px;" /> <apex:commandButton value="getDetails" action="{!getDetails}"/> </apex:OutputPanel>

 

public String dateOfEntry {get; set;} public PageReference getDetails(){ this.dateOfEntry= String.valueof(date.today()); return null; }

 

All Answers

Anand@SAASAnand@SAAS

Set the value of "data1" value in your controller to the value you want to display on the page. setting the parameter does'nt help. The code in your controller might look like this:

 

public PageReference getDetails(){//do any SOQL/additional processingthis.data1='Autopopulated value';return null;}

 

 

 

PrasenPrasen
I have set the data already like this.setData1() function yet it is not showing
PrazPraz

This is what I have done again:

 

in Apex class

 

public PageReference getDetails(){

      this.dateOfEntry= date.today();

     
return null;

 

 

and in visualforce I did the following thing

<Table>

 <tr><td>

<apex:outputPanel style="width:100px;">
                <apex:inputText value="{!dateOfEntry}" id="id1" style="width:100px;" />
            </apex:outputPanel>

</td></tr>

</Table>

 

This is the simplest thing for autopopulation but yet it is not populating.

 

Please check!!!

PrazPraz
dateofEntry is not a sObject field rather it's a field belonging to apex class...
visualforce_devvisualforce_dev

This code is working for me

 

<apex:OutputPanel style="width:100px;"> <apex:inputText value="{!dateOfEntry}" id="id1" style="width:100px;" /> <apex:commandButton value="getDetails" action="{!getDetails}"/> </apex:OutputPanel>

 

public String dateOfEntry {get; set;} public PageReference getDetails(){ this.dateOfEntry= String.valueof(date.today()); return null; }

 

This was selected as the best answer
PrazPraz
Thanks Boss...I got it!!!
symantecAPsymantecAP

This is a very good example. I have similiar kind of doubt.May be i can get help.

 

I have created a VF page. It has 3 fields. Prodcut Name , Product Family, Product description.

PRODUCT NAME is a lookup field to an object PRODUCT INFORMATION.

whenever Product Name is chosen it should auto populate Product Family and Product Description.

 

How is this acheived.

PrazPraz

try to save product name from a sObject field to a apex class field and then in apex class make a query to get the details for each field.

 

set the values in the apex class 

 

and keep page reference as null..

 

there you go...

 

 

try the sample code above as well!!!

 

symantecAPsymantecAP
wow...well...lemme try this...:)....thank u