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
sreelekhasreelekha 

To display the values of record from pageblock table to inputText fields in the same page

Hi,

I have created a vf page with two pageblocks .

One "pageBlock" contains "inputText" fields with Save Button.Other Contains a pageBlock table with "Edit" link in each row.

Here when i  click on "Save" button then it is saved to database and automatically updated in the below "PageBlock Table" in the same page.

Now i have the requirement,

when i click on "Edit" link on the particular row of the "PageBlockTable" then automatically the values of each cell of table set to respected "inPutText" fields in the above "PageBlock".

can any one reply me please?

Rohit_SFDCRohit_SFDC

can you please share your code, so that we can help you in this problem

 

sreelekhasreelekha

//Here is the code i wrote 

public class TestController1
{
       public PageReference getAccount() {
        return null;
    }


    //TestController t=new TestController();
  public String sname{get;set;}
  public Double inumber{get;set;}
  public String scountry{get;set;}
  public String sid{get;set;}
  public PageReference recSave()
  {
   Departments__c dep= new Departments__c(id=sid,Name=sname,No_of_Employees__c=inumber,Countries__c=scountry);
   insert dep;
   //system.debug('------------>'+sid);
   return null;
  }
  List<Departments__c> a;
  public List<Departments__c> geta()
  {
    a=[select name,id,No_of_Employees__c,Countries__c from Departments__c];
   //system.debug('departmentrecords'+a);
   return a;
  }
 
    }
---------------------------Page----------------------------------------------------------------------------
<apex:page controller="TestController1" id="pg">
<apex:form id="f1">
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!recSave}" value="save"/>
</apex:pageBlockButtons>

<apex:pageBlockSection >
<apex:outputLabel >Name :</apex:outputLabel>
<apex:inputText value="{!sname}" required="true"/>
<apex:outputLabel >No_Of_Employees :</apex:outputLabel>
<apex:inputText value="{!inumber}" required="true"/>
<apex:outputLabel >Country:</apex:outputLabel>
<apex:selectList id="chooseColor" value="{!scountry}" size="1" required="true">
            <apex:selectOption itemValue="none" itemlabel="--None--"></apex:selectOption>
            <apex:selectOption itemValue="india" itemLabel="India"/>
            <apex:selectOption itemValue="usa" itemLabel="USA"/>
            <apex:selectOption itemValue="china" itemLabel="China"/>
</apex:selectList>
<apex:outputText value="{!sid}" rendered="false"/>
</apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock id="pb">
<apex:pageBlockTable value="{!a}" var="ab" id="pt">
<apex:column value="{!ab.name}"/>
<apex:column value="{!ab.No_of_Employees__c}"/>
<apex:column value="{!ab.Countries__c}"/>
<apex:column value="{!ab.id}"  id="rid"/>
<apex:column Headervalue="Action"><apex:outputLink title="" value="/{!ab.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink></apex:column>
<apex:column Headervalue="Actiion"><apex:commandButton value="Edit"/></apex:column>
<!--<apex:column><apex:outputLink value="/{!ab.id}" >Edit1</apex:outputLink></apex:column>-->


</apex:pageBlockTable>
</apex:pageBlock>

</apex:form>
</apex:page>

rohitsfdcrohitsfdc

hi,

Few things to consider in your code

 

1) There is no need to take getter setter for every field. If that field is of some Custom or standard object, you can simply create a instance of that object and call that instance from VF page. for example in the following code

vf page:
<apex:inputField value="{!Account.name}" required="true"/>

Controller:
public Account getAccount(){
    return acc;
    }

 in that way, you can call any field exists in account object by calling it as {!account.fieldAPIname}

 

i have modified your code as per the account object. you can use any object by replacing account with your object name.

 

VF page:

<apex:page controller="TestController1" id="pg">
<apex:form id="f1">
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!recSave}" value="save"/>
</apex:pageBlockButtons>

<apex:pageBlockSection >
<apex:inputField value="{!Account.name}" required="true"/>
<apex:inputField value="{!account.No_of_employees__c}" required="true"/>
<apex:pageBlockSectionItem ><apex:outputLabel >Country:</apex:outputLabel>
<apex:selectList id="chooseColor" value="{!account.Countries__c}" size="1" required="true">
            <apex:selectOption itemValue="none" itemlabel="--None--"></apex:selectOption>
            <apex:selectOption itemValue="india" itemLabel="India"/>
            <apex:selectOption itemValue="usa" itemLabel="USA"/>
            <apex:selectOption itemValue="china" itemLabel="China"/>
</apex:selectList></apex:pageBlockSectionItem>

</apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock id="pb">
<apex:pageBlockTable value="{!a}" var="ab" id="pt">
<apex:column value="{!ab.name}"/>
<apex:column value="{!ab.No_of_employees__c}"/>
<apex:column value="{!ab.Countries__c}"/>
<apex:column value="{!ab.id}"  id="rid"/>
<apex:column Headervalue="Actiion"><apex:outputLink title="" value="/apex/testController1_page?id={!ab.id}" style="font-weight:bold">Edit</apex:outputLink>
</apex:column>
<!--<apex:column><apex:outputLink value="/{!ab.id}" >Edit1</apex:outputLink></apex:column>-->

</apex:pageBlockTable>
</apex:pageBlock>

</apex:form>
</apex:page>

 Controller:

public class TestController1
{

Account acc;    
    public TestController1() {
    ID id =ApexPages.currentPage().getParameters().get('id');
    if(id!=null)
    acc=[select name, countries__c, no_of_employees__C from account where id=:id];
    else
    acc=new Account();
    }
    
    public Account getAccount(){
    return acc;
    }


       
    


    //TestController t=new TestController();
    public PageReference recSave()
  {
      upsert acc;
      acc=new Account();
   //system.debug('------------>'+sid);
   return null;
  }
  List<Account> a;
  public List<Account> geta()
  {
    a=[select name,id,No_of_Employees__c,Countries__c from Account];
   //system.debug('departmentrecords'+a);
   return a;
  }
 
    }