function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mritzmritz 

using apex:repeat with inputText

I want to save values from dynamically generated input text into list<decimal> using repeat.
 please have a look on the following code and suggest changes.
 
Apex Class

public class myClass1{

        public string out1{get;set;}
        public list<decimal> capitals{get;set;}
        public list<decimal> revenues{get;set;}
                
        public myClass1(){
            out1='No way';
            capitals=new list<decimal>(5);
            revenues=new list<decimal>(5);
            for(integer i=0;i<5;i++){
                capitals[i]=revenues[i]=0;
            }
        }
        public void goDynamic(){
           out1=String.valueOf(capitals[1]);
        }
}


Visual Force Page

<apex:page controller="myClass1" showHeader="false" doctype="HTML-5.0">
    <apex:form id="form">
        <apex:tabPanel >
            <apex:tab label="one">
                <p>Tab one Content</p>
                <apex:outputtext id="out1" value="{!out1}" escape="false"/>
                <apex:commandButton value="addRow"  rerender="dataTable,out1"/>
                <apex:commandButton value="goDynamic" action="{!goDynamic}" rerender="dataTable,out1,rpt"/>
                <table id="dataTable" style="border:2px solid green">
                                     
                    <tr>
                        <th colspan="2">Capital</th>
                        <th colspan="2">Revenue</th>
                    </tr>
                    <apex:repeat value="{!capitals},{!revenue}" var="c,r" id="rpt">
                    <tr>
                        <td colspan="2"><apex:inputtext value="{!capitals[c]}"/></td>
                        <td colspan="2"><apex:inputtext value="{!revenues[r]}" /></td>

                    </tr>
                    </apex:repeat>    
                </table>
            </apex:tab>
            <apex:tab label="two">
            
            </apex:tab>
        </apex:tabPanel>
    </apex:form>
    


    
    
</apex:page>

What i want to acheive is that i can gather input values for "Capitals" and  "revenues" from the user and save it in apex and do some calculation on it.

I know that apex:repeat value="{!capitals},{!revenues}" is not working.
But i dnt know any approach to gather input in two lists simultaneously.

Any solution based on maps will be fine.
 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi mritzi,

Please use wrapper class.
See this link https://developer.salesforce.com/page/Wrapper_Class

Let us know if it helps.
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Mirtizi,

For your case it would be .
public wrapperRevenueAndCapital{
		public string out1{get;set;}
        public list<decimal> capitals{get;set;}
        public list<decimal> revenues{get;set;}
		
		public wrapperRevenueAndCapital(){
			this.out1 =out1;
			this.capitals =capitals;
			this.revenues = revenues;
		}
	}

Let us know if it helps.
mritzmritz
But i have various other functions in this class.

How to implement this within a class?
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi mritzi,

Use this as Inner Class.
 
mritzmritz
is the following lines syntatically correct.
(Given that i want to store 5 different values in each list i.e capitals & revenues)
<apex:repeat value="{!capitals},{!revenue}" var="c,r" id="rpt">
	                    <tr>
	                        <td colspan="2"><apex:inputtext value="{!capitals[c]}"/></td>
	                        <td colspan="2"><apex:inputtext value="{!revenues[r]}" /></td>
	                    </tr>
</apex:repeat>

Suggest changes if any.
 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
 Hi ,

It would be great if you practice wrapper class from https://developer.salesforce.com/page/Wrapper_Class

and then use it for your requirement.