You need to sign in to do that
Don't have an account?
Ty Whitfield
Issue pulling Visualforce variable into Apex
I'm clearly missing something in this process. I have a VF page that looks like this
What I would like to have happen is for the "Points Remaining" to total the number of "Found xx Total Exeuction Agent Points" minus the PakSize Input text amount.
Problems:
Apex Code:
What I would like to have happen is for the "Points Remaining" to total the number of "Found xx Total Exeuction Agent Points" minus the PakSize Input text amount.
Problems:
- With my code below, I don't understand why on page load, it processes the getCount() Method.
- I have been unsuccessful in passing the input field (pak) to Apex
<table > <tr> <td colspan="10"> <b> <apex:outputText value="Found {!Text(newOpps.Quantity)} Total Execution Agent Points " id="pointsTotal" /> <br /> <apex:outputText value="Points Remaining: {!count}" id="pointsRemaining" label=""/> </b> <hr /> </td> </tr> <th><b>Quantity</b></th> <th></th> <th><b>PakSize (Points)</b></th> <tr> <td> <apex:inputText id="quantity" required="true" /> </td> <td rowspan="20" style="width:50px"> </td> <td> <apex:outputpanel id="panel1"> <apex:inputText id="pak" value="{!pak}" /> <apex:actionSupport event="onchange" action="{!getCount}" status="counterStatus2" rerender="pointsRemaining"/> </apex:outputpanel> <apex:actionStatus id="counterStatus2" startText=" (Calculating...)" stopText=" (Completed)"/> </td> </tr> <tr> <td colspan="3"> <center> <apex:commandButton id="cmdaddLine" disabled="{!showButtons}" value="Add Another Multiple" /> </center> </td></tr> <tr> <td colspan="3"> <hr /> </td></tr> <tr> <td colspan="2"> <apex:commandButton id="cmdupdateOpp" disabled="{!showButtons}" value="Update Opportunity" /> </td> <td> <apex:commandButton id="cmdCancel" onclick="window.history.go(-1); return false;" value="Cancel" /> </td></tr> <!-- </apex:repeat> --> </table>
Apex Code:
public class SplitExecutionAgentController { @AuraEnabled public Boolean showButtons {get;set;} Integer pointsTotal = 0; Public Integer points {get;set;} Integer count = 0; Public Integer pak {get;set;} // input text1 value from vf public PageReference setParams() { return null; } public OpportunityLineItem getNewOpps() { OpportunityLineItem A; A = [SELECT Id, Quantity, PricebookEntryID, TotalPrice, UnitPrice, ListPrice, Description FROM OpportunityLineItem WHERE PricebookEntry.Name LIKE '%Execution Agent%' AND OpportunityId = :System.currentPageReference().getParameters().get('Id')]; pointsTotal = Integer.valueOf(A.Quantity); points = Integer.valueOf(A.Quantity); count = Integer.valueOf(A.Quantity); pak = 0; return A; } public Integer getCount() { points = pointstotal - pak ; return points; } }
I have checked and its working fine :-
check this one :-
<apex:page controller="testRerender">
<apex:form>
<table>
<tr>
<td colspan="10">
<b>
<apex:outputText value="Points Remaining: {!points}" id="pointsRemaining" label=""/>
</b>
<hr/>
</td>
</tr>
<tr>
<td>
<apex:outputpanel id="panel1">
<apex:inputText id="pak" value="{!pak}" />
<apex:actionSupport event="onchange" action="{!calcPoints}" status="counterStatus2" rerender="pointsRemaining" />
</apex:outputpanel>
<apex:actionStatus id="counterStatus2" startText=" (Calculating...)" stopText=" (Completed)" />
</td>
</tr>
</table>
</apex:form>
</apex:page>
-----------------------------------------
public class testRerender{
public integer pak{get;set;}
public integer points{get;set;}
public testRerender(){
}
public void calcPoints(){
points = pak +15 ;
}
}
All Answers
- Getter and setter methods are called everytime there is a request from VFpage to controller.
- Use Public Integer count{get;set;} instead of Integer count = 0;
- Change the name fo the method from getCount to any other name.
Let me know if you need any help.VF
And the Apex Code
To get the values reflected on page Try to reRender the table in which you are using the points variable.
Regarding the reRender, isn't that what the actionSupport doing? If not, is there a better way?
I have checked and its working fine :-
check this one :-
<apex:page controller="testRerender">
<apex:form>
<table>
<tr>
<td colspan="10">
<b>
<apex:outputText value="Points Remaining: {!points}" id="pointsRemaining" label=""/>
</b>
<hr/>
</td>
</tr>
<tr>
<td>
<apex:outputpanel id="panel1">
<apex:inputText id="pak" value="{!pak}" />
<apex:actionSupport event="onchange" action="{!calcPoints}" status="counterStatus2" rerender="pointsRemaining" />
</apex:outputpanel>
<apex:actionStatus id="counterStatus2" startText=" (Calculating...)" stopText=" (Completed)" />
</td>
</tr>
</table>
</apex:form>
</apex:page>
-----------------------------------------
public class testRerender{
public integer pak{get;set;}
public integer points{get;set;}
public testRerender(){
}
public void calcPoints(){
points = pak +15 ;
}
}