You need to sign in to do that
Don't have an account?
Chanagan Sakulteera
I want to save all record to data base
Hi all,
I am new to visualforce. After query of records, I would like to update the same records with to the database but i am unable to save becuse there is no attribute receive data from the visualforce page.
This code vf page
<apex:page standardController="Product_Service__c" extensions="CostCalculationExtention">
<script language="javascript">
function IsNumeric(sText,obj){
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++){
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1){
IsNumber = false;
}
}
if(IsNumber==false){
alert("Input number only!!");
obj.value=sText.substr(0,sText.length-1);
}
}
</script>
<apex:sectionHeader Title="Cost Calculation" subtitle="{!theProduct.Name}"/>
<apex:form >
<apex:pageBlock title="Cost Calculation">
<apex:pageblockTable value="{!lstProductService}" var="lstPS">
<apex:column headerValue="Service">
<apex:outputField value="{!lstPS.Service__r.Name}"/>
</apex:column>
<apex:column headerValue="Client Exp - Adult">
<apex:inputField id="clientAdult" value="{!lstPS.Client_Expense_Adult__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
<apex:column headerValue="Client Exp - Child">
<apex:inputField id="clientChild" value="{!lstPS.Client_Expense_Child__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
<apex:column headerValue="T/L Exp">
<apex:inputField id="tlExp" value="{!lstPS.Tour_Leader_Expense__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
<apex:column headerValue="L/G Exp">
<apex:inputField id="lgExp" value="{!lstPS.Local_Guide_Expense__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
<apex:column headerValue="Coach">
<apex:inputField id="coach" value="{!lstPS.Coach__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
</apex:pageblockTable>
<br/>
<center><apex:commandButton value="Save"/></center>
</apex:pageBlock>
</apex:form>
</apex:page>
This picture result code.
This code controller.
public with sharing class CostCalculationExtention{
//-- Open Page --\\
public Product__c theProduct {get; set;}
private String productId {get; set;}
public Product_Service__c[] lstProductService {get; set;}
//-- Open Page --\\
//-- Constructor --\\
public CostCalculationExtention(ApexPages.StandardController controller) {
productId = apexpages.currentpage().getparameters().get('CF00NO0000001EtuG_lkid');
//system.debug('ProductId : ' + productId);
theProduct = [select id, name from Product__c where id =: productId];
//system.debug('The Product : ' + theProduct);
lstProductService = [select id, name, Service__r.Name, Client_Expense_Adult__c, Client_Expense_Child__c, Tour_Leader_Expense__c, Local_Guide_Expense__c, Coach__c from Product_Service__c where Product__r.id =: theProduct.Id];
//system.debug('List Product_Service : ' + lstProductService);
}
//-- Constructor --\\
//-- Save --\\
public PageReference onSave(){
return new PageReference('/' + ApexPages.currentPage().getParameters().get('CF00NO0000001EtuG_lkid'));
}
//-- Save --\\
}
I want to know what they should do next .
Thank you!!.
I am new to visualforce. After query of records, I would like to update the same records with to the database but i am unable to save becuse there is no attribute receive data from the visualforce page.
This code vf page
<apex:page standardController="Product_Service__c" extensions="CostCalculationExtention">
<script language="javascript">
function IsNumeric(sText,obj){
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++){
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1){
IsNumber = false;
}
}
if(IsNumber==false){
alert("Input number only!!");
obj.value=sText.substr(0,sText.length-1);
}
}
</script>
<apex:sectionHeader Title="Cost Calculation" subtitle="{!theProduct.Name}"/>
<apex:form >
<apex:pageBlock title="Cost Calculation">
<apex:pageblockTable value="{!lstProductService}" var="lstPS">
<apex:column headerValue="Service">
<apex:outputField value="{!lstPS.Service__r.Name}"/>
</apex:column>
<apex:column headerValue="Client Exp - Adult">
<apex:inputField id="clientAdult" value="{!lstPS.Client_Expense_Adult__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
<apex:column headerValue="Client Exp - Child">
<apex:inputField id="clientChild" value="{!lstPS.Client_Expense_Child__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
<apex:column headerValue="T/L Exp">
<apex:inputField id="tlExp" value="{!lstPS.Tour_Leader_Expense__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
<apex:column headerValue="L/G Exp">
<apex:inputField id="lgExp" value="{!lstPS.Local_Guide_Expense__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
<apex:column headerValue="Coach">
<apex:inputField id="coach" value="{!lstPS.Coach__c}" onkeypress="IsNumeric(this.value,this)"/>
</apex:column>
</apex:pageblockTable>
<br/>
<center><apex:commandButton value="Save"/></center>
</apex:pageBlock>
</apex:form>
</apex:page>
This picture result code.
This code controller.
public with sharing class CostCalculationExtention{
//-- Open Page --\\
public Product__c theProduct {get; set;}
private String productId {get; set;}
public Product_Service__c[] lstProductService {get; set;}
//-- Open Page --\\
//-- Constructor --\\
public CostCalculationExtention(ApexPages.StandardController controller) {
productId = apexpages.currentpage().getparameters().get('CF00NO0000001EtuG_lkid');
//system.debug('ProductId : ' + productId);
theProduct = [select id, name from Product__c where id =: productId];
//system.debug('The Product : ' + theProduct);
lstProductService = [select id, name, Service__r.Name, Client_Expense_Adult__c, Client_Expense_Child__c, Tour_Leader_Expense__c, Local_Guide_Expense__c, Coach__c from Product_Service__c where Product__r.id =: theProduct.Id];
//system.debug('List Product_Service : ' + lstProductService);
}
//-- Constructor --\\
//-- Save --\\
public PageReference onSave(){
return new PageReference('/' + ApexPages.currentPage().getParameters().get('CF00NO0000001EtuG_lkid'));
}
//-- Save --\\
}
I want to know what they should do next .
Thank you!!.
your command button calls the standard Save method from the standard controller, not the save method of your extension, so you have to call your method (the syntax of the controller method call using {!...}) The additionnal code you posted is also necessary, because if you do not execute a DML statement (insert, update, upsert) no input will be saved to the database.
Hope this helps
Gil
Question Solved ? Please mark as the best answer to help other users !
All Answers
public PageReference onSave(){
upsert(lstProductService);
return new PageReference('/' + ApexPages.currentPage().getParameters().get('CF00NO0000001EtuG_lkid'));
}
//-- Save --\\
I tried to add this code to the above but after save nothing happened. please help me!!.
your command button calls the standard Save method from the standard controller, not the save method of your extension, so you have to call your method (the syntax of the controller method call using {!...}) The additionnal code you posted is also necessary, because if you do not execute a DML statement (insert, update, upsert) no input will be saved to the database.
Hope this helps
Gil
Question Solved ? Please mark as the best answer to help other users !
It has correct.
Thank you very much Gil Gourévitch.