2012-06-15 42 views
0

我對visualforce/salesforce很陌生,我是一個非常可怕的初學者,所以請原諒我可能很容易的問題。Visualforce頁面沒有執行動作

我正在創建一個頁面來跟蹤會議預算。基本上用戶輸入在一個字段中設置了多少預算,然後輸入實際成本,然後在第三個字段中,SF/VF應該計算2個數字並顯示差異。我設置了字段(正確地我認爲這很簡單)並設置了一個頁面。現在,當您將信息輸入到字段並單擊保存時,不會發生任何事情。

這是我的頭腦,我試圖找到文獻中的答案,但沒有很多運氣。

下面是代碼:

<apex:page standardController="Conference__c" sidebar="true"> 
    <apex:sectionHeader title="Conference Budget" subtitle="{!Conference__c.name}"/> 
     <apex:form > 
      <apex:pageBlock title="Conference Budget" id="thePageBlock" mode="edit"> 
      <apex:pageBlockButtons > 
        <apex:commandButton value="Save" action="{!save}"/> 
        <apex:commandButton value="Cancel" action="{!cancel}"/>     
      </apex:pageBlockButtons> 
      <apex:actionRegion > 
<apex:pageBlocksection title="Conference Budget"> 
      <apex:panelGrid columns="4" width="400px" cellspacing="5px">     

       <apex:outputText value="Item" id="Item"/> 
       <apex:outputText value="Budgeted" id="Budgeted"/> 
       <apex:outputText value="Actual" id="Actual"/> 
       <apex:outputText value="Difference" id="Difference"/> 

       <apex:outputText value="Advertising" id="advertising"/> 
       <apex:inputField value="{!Conference__c.Advertising_b__c}"/> 
       <apex:inputField value="{!Conference__c.Advertising_a__c}"/> 
       <apex:inputField value="{!Conference__c.Advertising_d__c}"/> 
<apex:outputText value="Totals" id="totals"/> 
       <apex:inputField value="{!Conference__c.Total_Cost_b__c}"/> 
       <apex:inputField value="{!Conference__c.Total_Cost_a__c}"/> 
       <apex:inputField value="{!Conference__c.Total_Cost_d__c}"/> 


       <apex:actionStatus startText="applying value..." id="status"/> 

       </apex:panelGrid> 
       </apex:pageBlocksection> 
           </apex:actionRegion> 



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

回答

0

實現主要的事情是,Salesforce的(除非你有一些類型的工作流程建立的)是不會自動計算這些領域。另外,簡單地在操作區域內保存記錄不會保存記錄,重新加載記錄並再次顯示頁面。就我所知,保存將用戶重定向到記錄詳細信息頁面。

對於這個簡單的計算,如果你想Ti計之前以保存記錄,我只想用一些簡單的JavaScript

<apex:page standardController="Conference__c" sidebar="true"> 
    <!-- I use JQUERY because Salesforce IDs are very difficult to utilize in standard JS --> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script> 
    <script type="text/javascript"> 
    var $j = jQuery.noConflict(); // SFDC uses $ so we need to assign jQuery to something else 
    function recalcAd() { 
     try{ 
     var budget = parseFloat($j("input[id$='ad-b']").val()); 
     var actual = parseFloat($j("input[id$='ad-a']").val()); 
     $j("input[id$='ad-d']").val(budget - actual); 
     } catch (e) { 
     $j("input[id$='ad-d']").val(""); 
     } 
    } 
    function recalcTot() { 
     try{ 
     var budget = parseFloat($j("input[id$='tot-b']").val()); 
     var actual = parseFloat($j("input[id$='tot-a']").val()); 
     $j("input[id$='tot-d']").val(budget - actual); 
     } catch (e) { 
     $j("input[id$='tot-d']").val(""); 
     } 
    } 
    </script> 
    <apex:sectionHeader title="Conference Budget" subtitle="{!Conference__c.name}"/> 
    <apex:form > 
     <apex:pageBlock title="Conference Budget" id="thePageBlock" mode="edit"> 
     <apex:pageBlockButtons > 
      <apex:commandButton value="Save" action="{!save}"/> 
      <apex:commandButton value="Cancel" action="{!cancel}"/>   
     </apex:pageBlockButtons> 
     <apex:pageBlocksection title="Conference Budget"> 
     <apex:panelGrid columns="4" width="400px" cellspacing="5px"> 
      <apex:outputText value="Item" id="Item"/> 
      <apex:outputText value="Budgeted" id="Budgeted"/> 
      <apex:outputText value="Actual" id="Actual"/> 
      <apex:outputText value="Difference" id="Difference"/> 
      <apex:outputText value="Advertising" id="advertising"/> 
      <apex:inputField id="ad-b" value="{!Conference__c.Advertising_b__c}" onChange="recalcAd(); return true;"/> 
      <apex:inputField id="ad-a" value="{!Conference__c.Advertising_a__c}" onChange="recalcAd(); return true;"/> 
      <apex:inputField id="ad-d" value="{!Conference__c.Advertising_d__c}"/> 
      <apex:outputText value="Totals" id="totals"/> 
      <apex:inputField id="tot-b" value="{!Conference__c.Total_Cost_b__c}" onChange="recalcTot(); return true;"/> 
      <apex:inputField id="tot-a" value="{!Conference__c.Total_Cost_a__c}" onChange="recalcTot(); return true;"/> 
      <apex:inputField id="tot-d" value="{!Conference__c.Total_Cost_d__c}"/> 
     </apex:panelGrid> 
     </apex:pageBlocksection> 
    </apex:pageBlock> 
</apex:form> 
</apex:page> 

在代碼中,我添加了一些一些腳本將重新計算總數,並刪除似乎不必要的行動區域。我無法測試它(因爲我沒有在我的帳戶中設置該對象),但我認爲它應該適用於您。