You need to sign in to do that
Don't have an account?

Updating a row in pageblocktable
Hi,
I have a subclass wrapper that I use to populate a pageblocktable on the VF page. When I take action on the row I am able to pass the row id to the controller and do some work that I need to do.
The problem is I know want to update the row on the table with data. I think I need to get the wrapper class row and update it and my action refreshes the pageblocktable so I think it should refresh and show the change. The problem is I am having trouble figuring out how to use my wrapper class list and get to the specific related row so I can update the field level data in the wrapper class record.
Since it is a list I am not certain I can do this. Any idea on this would be helpful.
I have a subclass wrapper that I use to populate a pageblocktable on the VF page. When I take action on the row I am able to pass the row id to the controller and do some work that I need to do.
The problem is I know want to update the row on the table with data. I think I need to get the wrapper class row and update it and my action refreshes the pageblocktable so I think it should refresh and show the change. The problem is I am having trouble figuring out how to use my wrapper class list and get to the specific related row so I can update the field level data in the wrapper class record.
Since it is a list I am not certain I can do this. Any idea on this would be helpful.
As far as I understood you want to be able to find the row that you clicked on and change fields on the car record? If that's the case then your controller methods should look something like this:
All Answers
Also, if the list is an issue and you can't identify the record, you can also use a map and apex repeat to build the table.
So below is the mark up. It uses the standard Contact object and a custom object called Car__c.
My wrapper class encapsulates the car__c object and expans on that with a few objects like status and two booleans for holding the button's value when clicked.
So when one of the buttons are clicked I call a method and I am passing the method to the table row id of thet car__c id. I can't seem to figure out how I can get the other details for that matching id in the wprCar list and update the fields.
Is there a way I can pass the entire table row data? If I could do that then I think what I have access to in my method that gets called on the button click would allow me to update the record.
<apex:page title="Cars" tabStyle="Contact" standardController="Car__c" Extensions="car_Controller" recordSetVar="car">
<apex:sectionHeader title="Car Picker" subtitle="{!Contact.Name}"/>
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
.....
.....
.....
<apex:pageblockSection title="Cars" collapsible="false" Columns="1" id="pbs3">
<apex:pageblockTable value="{!wprCarList}" var="CarWpr" id="pbt1">
<apex:column headerValue="Action" width="150">
<apex:commandButton action="{!StartCar}" value="Start" disabled="{!carWpr.Started}" reRender="pbs1,pbs3">
<apex:param assignTo="{!currentId}" name="carId" value="{!CarWpr.carId}"/>
</apex:commandButton>
<apex:commandButton action="{!StopCar}" value="Stop" disabled="{!carWpr.Stopped}" reRender="pbs1,pbs3">
<apex:param assignTo="{!currentId}" name="carId" value="{!carWpr.carId}"/>
</apex:commandButton>
</apex:column>
<apex:column value="{!carWpr.Status}" headerValue="Status" width="100"/>
<apex:column value="{!carWpr.car.Name}" width="400"/>
<apex:column value="{!carWpr.car.color__c}"/>
</apex:pageblockTable>
</apex:pageblockSection>
....
....
....
//CONTROLLER
public with sharing class car_Controller {
public List<wprCar> wprCarList {get; set;}
....
....
....
// Wrapper class for car table
public class wprCar {
public Car__c Car {get; set;}
public Id CarId {get; set;}
public Boolean started {get; set;}
public Boolean stopped {get; set;}
public String color {get; set;}
public wprCar( Car__c d ) {
CarId = d.Id;
Car = d;
started = false;
stopped = false;
color = '';
}
}
}
As far as I understood you want to be able to find the row that you clicked on and change fields on the car record? If that's the case then your controller methods should look something like this: