+ Start a Discussion
Jyothsna ReddyJyothsna Reddy 

How to add values entered in textbox ,surrounded by apex:repeat as shown <apex:repeat ><apex:inputtext/></apex:repeat> to the list in controller

Hi all,

Here I am using Custom controller. 

Since there are 5  records in  mappingList  .It is showing 5 textboxes.How can I add the text entered in textboxes to List.
I am getting only the last value in controller.Here I dontknow how to add these values to array....
<apex:pageBlock >
    <apex:repeat value="{!mappingsList}" var="a">
         
         <apex:inputText value="{!textarray}" id="in"/><br/>
    </apex:repeat>
   <apex:commandButton value="Save" action="{!myaction}"/>
</apex:pageblock>



-----Please  attach  the printscreen----------
 Ps
logontokartiklogontokartik
Hello Jyothsna,

You need to add {!a} in your inputText
<apex:pageBlock >
    <apex:repeat value="{!mappingsList}" var="a">
         <apex:inputText value="{!a}" id="in"/><br/>
    </apex:repeat>
   <apex:commandButton value="Save" action="{!myaction}"/>
</apex:pageblock>

Thank you

Kartik



Ramu_SFDCRamu_SFDC
Follow the instructions provided in the below documentation

https://www.salesforce.com/us/developer/docs/pages/Content/pages_dynamic_vf_maps_lists.htm
Jyothsna ReddyJyothsna Reddy
Hi   logontokartik  thanq for reply.
I tried urs code but I got error as below
Error Error: Unknown property 'a'
Jyothsna ReddyJyothsna Reddy
Hi Ramu,

I tried the link which u sent.
In that I observed one thing
<apex:inputField value="{!mapToAccount[accNum].Name}" />

User-added image


Here in text they are displaying the values on accountNames.But I want to enter  my own text in that textbox and
then I want to add these entered values to an array .how to acheive this....
logontokartiklogontokartik
Hello Jyothsna,

Can you tell me how the mappingsList is defined in controller?

Thank you
Jyothsna ReddyJyothsna Reddy
Hi ,
MappinList  method definition is here.Plz have a glance
public List<Contact> mapLs{get;set;}
public List<Contact> getMappingList(){
     mapLs=[SELECT Name From Contact Limit 5];
    return mapLs;
}


logontokartiklogontokartik
So its a list of contacts, ok. 

I would suggest you to go through the Force.com Fundamentals and workbooks once. 

For your problem though, 

Not sure if there is a setter method in your controller if you dont have one please add one 

public void setMappingList(List<Contact> value){
      this.mapLs = value;
}

Another issue with your SOQL is name is a read only field on Contact, instead you would need to update firstname and lastname.

public List<Contact> getMappingList(){
     mapLs=[SELECT Name, FirstName, LastName From Contact Limit 5];
    return mapLs;
}

In your Visualforce page now, you can write something like this
<apex:pageBlock >
    <apex:repeat value="{!mappingList}" var="a">
         <apex:inputText value="{!a.FirstName}" id="firstName"/>&nbsp;
         <apex:inputText value="{!a.LastName}" id="lastName"/><br/>
    </apex:repeat>
   <apex:commandButton value="Save" action="{!myaction}"/>
</apex:pageblock>

Please make sure its mappingList vs mappingsList as I have seen in your first comment you mentioning it as mappingsList


Hope this helps.

Thank you




Jyothsna ReddyJyothsna Reddy

Actually,I dont  want to use "a.firstname "here as a value
<apex:inputtext value="{!textarray}" rendered="if(a.firstName=='sai',true,false)"/>
so whenever firstname is sai then only this text box will display and whatever I entered here I want it to add to array