You need to sign in to do that
Don't have an account?
Sami Shakith
How to get multiple variable for inputfield within pageBlockTable
Hi,
I am trying to create a VF page which calculates the NetAmount based on Buying Price and Discount in listed record.
My VF page is
Ok button method is like that
I am using Wrapper class for list the records.
That VF page will display the details of the opportunity and Net amount for the listed record below. I gave PageBlockTable for getting records and also I include a textfield to get discount amount. Here i gave single variable for the textfield. If only one record is listed means it works fine. But for multiple records it will take only the last value for Net amount calculation. I am getting multiple values using single variable name. I dont know how to get the multiple variables. I need someone help. Suggestion please.
I am trying to create a VF page which calculates the NetAmount based on Buying Price and Discount in listed record.
My VF page is
<apex:page StandardController="Opportunity" extensions="EQuoteController"> <apex:form > <apex:pageBlock > <apex:pageBlockSection columns="1"> <apex:outputField label="User Name" value="{!opportunity.Name}"/> <apex:outputField label=" Account Name" value="{!Opportunity.AccountId}"/> <apex:outputField label="Email Id" value="{!Opportunity.Email__c}"/> <apex:outputText Label="Net Amount" Value="{!NetAmount}"/> </apex:pageBlockSection> Related price details for {!Opportunity.name}: <apex:pageblockSection title="Price Details" collapsible="false" columns="2"> <apex:pageBlockTable value="{!selectedlist}" var="price" id="table2" title="Selected Price Details"> <apex:column value="{!price.Name}" headerValue="Name"/> <apex:column value="{!price.Buying_Price__c}" headerValue="Buying Price"/> <apex:column headerValue="Discount"> <apex:inputText value="{!Discount}"/> </apex:column> <apex:column headerValue="Action"> <apex:commandButton value="ok" action="{!OkDiscount}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Ok button method is like that
public void OkDiscount(){ price = new price_details__c(); DisAmount=0; NetAmount=0; selectedList = new List<Price_Details__c>(); for(wrapPrice wrapPriceObj : wrapPriceList) { if(wrapPriceObj.selected == true) { selectedList.add(wrapPriceObj.pds); pid=wrapPriceObj.pds.id; price=[select id, name, Buying_price__c from Price_details__c where id=:pid]; NetAmount=NetAmount+price.Buying_price__c; DisAmount=(Discount*price.Buying_price__c)/100; NetAmount=NetAmount-DisAmount; } } }
I am using Wrapper class for list the records.
That VF page will display the details of the opportunity and Net amount for the listed record below. I gave PageBlockTable for getting records and also I include a textfield to get discount amount. Here i gave single variable for the textfield. If only one record is listed means it works fine. But for multiple records it will take only the last value for Net amount calculation. I am getting multiple values using single variable name. I dont know how to get the multiple variables. I need someone help. Suggestion please.
You already stated what your problem is, you have one discount per item yet you only have one discount variable.
The best solution is to add discount to your Price object (or even the wrapPriceList object if you like).
Bind the discount in the VF page to the Price.discount.
Then in your formula
Change DisAmount=(Discount*price.Buying_price__c)/100;
to
DisAmount=(price.Discount*price.Buying_price__c)/100;
then you should be set.
Thx
By the way, you should post your VF code so I can see what is the discount bound to now,
I am guessing all of it is bound to {!Discount} via inputtext tag.
It looks like you are using Pageblock with Pageblocktable and apex:column to show your 3 columns iterating through the Price_details__c object in the Pageblocktable.
All Answers
How are you setting the wrapPrice.selected member? I do not see an input column for that in your Price Details pageBlockTable but your OkDiscount() action method is checking for it. Unless you have some other methods setting that value to true then I do not see any way this code would ever output the desired results. I think it would be best for you to post the full controller code, the full wrapper class code as well as any page code you may have taken out before posting this.
You need to post the whole code if you want help.
extensions="EQuoteController"? where's the code?
wrapPriceList --> where is this populated?
I still am not sure what you are asking for? What is the issue? What are you getting? vs What are you expecting?
Screen prints or values will be helpful
thx.
Please tell a solution.
You already stated what your problem is, you have one discount per item yet you only have one discount variable.
The best solution is to add discount to your Price object (or even the wrapPriceList object if you like).
Bind the discount in the VF page to the Price.discount.
Then in your formula
Change DisAmount=(Discount*price.Buying_price__c)/100;
to
DisAmount=(price.Discount*price.Buying_price__c)/100;
then you should be set.
Thx
By the way, you should post your VF code so I can see what is the discount bound to now,
I am guessing all of it is bound to {!Discount} via inputtext tag.
It looks like you are using Pageblock with Pageblocktable and apex:column to show your 3 columns iterating through the Price_details__c object in the Pageblocktable.
Hi william,
Thanks for your reply
You are rite. But i want to get the discount values without creating any field for it. Should i give any iterating loop for it? if it is means how can i?
What William said is spot on. Also, based on your code as well as your screenshot there is no reason to use a wrapper class. If you just add the discount field to your price details object then a lot of issues can be resolved here and you wouldn't even need code to get this done.
Is it not possible to calculate a discout without creating a field for discount? Because i dont want to create a field. Actually im redirecting this page from another VF page. So that only i used wraper class.
If you do not want a new field then you must add a new value to your inner wrapper class.
Once you have that updated you just need to change your selectedList collection to be a List<wrapPrice> and have your pageblock iterate over that.
Now, just update your apex column to point to the wrapPrice.discount instead of the discount member.
Once that is done you just need to tweak your OkDiscount() method to sum the wrapPrice.discount values and then use that to calculate your netAmount value.
The best solution is to add discount to your Price object (or even the wrapPriceList object if you like).
but if you don't want change the price object then you can bind your VF page to the wrapper object like Robert showed you above.
Thx
Otherwise, as a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
This will help keep the forum clean and help future users determine what answers are useful
and what answer was the best in resolving the user's issue.
Thanks
Controller class is here
Thanks