2
<apex:page controller="repeatlist"  showHeader="false" sidebar="false">
<apex:form >

        <apex:pageBlock >
            <apex:commandButton value="save" action="{!save}"/>
            <apex:pageBlockTable value="{!con}" var="cc">
            <apex:column headerValue="ID" width="50" breakBefore="true">
                <apex:outputtext >{!cc.id}</apex:outputtext>
            </apex:column>
              <apex:column headerValue="Firstname">
                  <apex:outputfield value="{!cc.Firstname}" >
                     <apex:inlineEditSupport event="onclick" />
                  </apex:outputfield>

              </apex:column>
              <apex:column headerValue="Modify">
                  <apex:commandButton value="save" action="{!savein}" />
              </apex:column>
              <apex:inputHidden value="{!cc.id}" id="dd" />
            </apex:pageBlockTable>
        </apex:pageBlock>


</apex:form>

Hi every one i need to edit individual records in the pageblock table but I dont have any idea about passing data to the controller on clicking save button.Can anyone help me in that? I have tried saving all records and it worked as charm.

public class repeatlist
{    
    List<Contact> con1 = new list<contact>();

    public list<Contact> getcon()
    {
        con1 = [select id, FirstName, Name from contact limit 20];
        return con1;
    }

    public pagereference save()
    {
        update con1;
        return null;
    }

    public pagereference savein()
    {
        system.debug('PGp::');
        return null;
    }
}
3
  • 1
    Can you show the code of the controller so that we can help you better?
    – mkorman
    Dec 22, 2015 at 8:03
  • I have added my code Dec 22, 2015 at 8:41
  • Thanks, that helps. Also, if you always return a null pagereference, you can make it a void method. It conveys your intent better.
    – mkorman
    Dec 22, 2015 at 9:04

2 Answers 2

1

You can add a boolean variable like Flag, when user is editing, make it True, and in Controller check, for which line(i.e. object ID), Flag is on, just save that object only.

And if you are getting associating/mapping Flag with object, then you can create your own wrapper class for that. e.g for Contact wrapper would be like:

class controller_class
{
  public class ContactWrapper
  {
     public Boolean Flag;
     public Contact c;

     ContactWrapper(Boolean Flag, Contact c)
     {
        this.c = c;
        this.flag = flag;
     }

     //you can add getter-setter method here, as per your req.
  }

}
2
  • I have tried that and it worked but i need to know if there is any other possible ways without using flags? Dec 22, 2015 at 9:33
  • There could be another work-around using JS with RemoteAction. But I think above method is simpler than the JS with RemoteAction. Let me explain in brief that, you can have an inline editing style option using JS, and pass the entry which have being editing to the helper class. And save that object. If you read RemoteAction concept, then you can easily understand what I want to say.
    – Ysr Shk
    Dec 22, 2015 at 11:21
0

You can use <apex:actionFunction /> for your requirement. <apex:actionFuntion /> can have argument and you can pass those argument to controller and then by using that argument you can get what records you want to update.

Like you can re-write your save button code in visual force page like this:-

<apex:commandButton value="save" action="saveRecord({!cc.id})" />

Now write an actionFunction just after apex:pageBlock tag

<apex:actionFunction name="saveRecord"  action="{!savein}" >
   <apex:param name="idField" assignTo="{!idOfRecord}" value="" />
</apex:actionFuntion>

This idOfRecord will be a public property in controller.

Now whenever you click on this save button, idOfRecord will have the proper Id of the record you want to update. You can pass multiple parameter if you want.

For again displaying newly updated record on you grid, you can use AJAX (Visual force have rendering for AJAX call).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .