You need to sign in to do that
Don't have an account?
sp13
update record in visualforce page table
how can i update a record in my visualforce page table?
my table is like this:
this is my vf page:
and this is the class:
my table is like this:
Name UnitPrice(inputfields) Link
Fuel1 50.00 Update Price
Fuel2 60.00 Update Price
Fuel1 50.00 Update Price
Fuel2 60.00 Update Price
this is my vf page:
<apex:page showHeader="false" sidebar="false" standardController="Fuel__c" extensions="FuelUpdateCX">
<apex:form >
<apex:messages />
<apex:pageBlock >
<apex:pageBlockTable value="{!Fuel}" var="f">
<apex:column value="{!f.Name}"/>
<apex:column headerValue="Unit Price">
<apex:inputField value="{!f.Unit_Price__c}"/>
</apex:column>
<apex:column width="10%">
<apex:commandLink action="{!updatePrice}" style="padding:1px 2px; font-weight:bold;">Update Price</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:form >
<apex:messages />
<apex:pageBlock >
<apex:pageBlockTable value="{!Fuel}" var="f">
<apex:column value="{!f.Name}"/>
<apex:column headerValue="Unit Price">
<apex:inputField value="{!f.Unit_Price__c}"/>
</apex:column>
<apex:column width="10%">
<apex:commandLink action="{!updatePrice}" style="padding:1px 2px; font-weight:bold;">Update Price</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
and this is the class:
public with sharing class FuelUpdateCX {
public FuelUpdateCX(ApexPages.StandardController controller) {}
public List<Fuel__c> getFuel() {
return[select id, Name, Unit_Price__c from Fuel__c ORDER BY Name];
}
public pageReference updatePrice() {
//update fuel here
return new PageReference('/apex/FuelUpdate');
}
public FuelUpdateCX(ApexPages.StandardController controller) {}
public List<Fuel__c> getFuel() {
return[select id, Name, Unit_Price__c from Fuel__c ORDER BY Name];
}
public pageReference updatePrice() {
//update fuel here
return new PageReference('/apex/FuelUpdate');
}
}
should i use wrapper? how can i update the price here?
Then use the <apex:param tag
<apex:commandLink action="{!updatePrice}" style="padding:1px 2px; font-weight:bold;">
<apex:param name="SelectedFuelId"
value="{!f.Id}"
assignTo="{!SelectedFuelId}"/>
Update Price</apex:commandLink>
Then update price is called, SelectedFuelId will be populated with the id of the fuel object you click the link of.
* You could replace SelectedFuelId by the complete object also to avoid having to query it again.
public PageReference updatePrice() {
Fuel__c newFuel = new Fuel__c();
newFuel = [select id, name, Unit_Price__c from Fuel__c where id=:SelectedFuelId];
update newFuel;
return new PageReference('/apex/FuelUpdate');
}
what do you think the problem is?