+ Start a Discussion
Ravi KRavi K 

how to bind list of dynamic boxes from VF page to controller, values are not binding when using action function with Immediate=true property

I have a requirement to capture list of names using Dynamic boxes on VF page. I am using action function for this, but behavior is getting changed based on attribute "Immediate" of action function. if Immediate="true" values are not binding to list showing blanks. if "false" its binding values correctly. But i have to use this with Immediate=true.

Below is my code: Controller:
public with sharing class DynamicTextbox {

public list<AUser> lstuser{get;set;} 

public DynamicTextbox(ApexPages.StandardController controller) {
     lstuser = new list<Auser>();
        lstuser.add(new Auser(''));
    }
    
public void AddName() { 
              lstuser.add(new Auser(''));
    }    
    
 public class Auser{    
    public string name{get;set;}    
        public Auser(string name){
        this.name=name;    
    }
 }
 

}

VF page:
<apex:page standardController="account" extensions="DynamicTextbox"> 
    <apex:form > 
        <apex:actionFunction id="AddAuthorizedUser" name="AddName" action="{!AddName}" reRender="Outpanel" immediate="true"/>
         <apex:outputPanel id="Outpanel" > 
            <apex:actionRegion >
                <apex:repeat value="{!lstuser}" Var="Auser" id="samrr"> 
                    <apex:inputtext value="{!Auser.name}" styleClass="form-control"/>
                </apex:repeat>
                <button type="button" onclick="AddName();">&nbsp;<B>+</b>&nbsp;</button> 
            </apex:actionRegion>
        </apex:outputPanel> 
    </apex:form> 
</apex:page>
 
Best Answer chosen by Ravi K
NagendraNagendra (Salesforce Developers) 
Hi Ravi,

If you use an action region - you can not need to process these validations that are required when adding a new row here like so:
<apex:page standardController="Account" extensions="DynamicTextBox"> 

    <apex:form id="form"> 
        <apex:pageBlock id="block" mode="mainDetail">
           <apex:pageblockSection columns="1">
                <apex:inputField value="{!Account.AccountNumber}" required="true"/>  
             </apex:pageBlockSection>
             <apex:outputPanel id="Outpanel" > 
                  <apex:actionRegion>             
                    <apex:repeat value="{!lstuser}" Var="Auser" id="samrr"> 
                        <apex:inputtext value="{!Auser.name}" styleClass="form-control"/>
                    </apex:repeat>
                    <apex:commandButton value="+" action="{!addName}" reRender="block"   />
                 </apex:actionRegion><br />
                 <apex:outputText value="List size: {!lstUser.size}" />
            </apex:outputPanel> 
        </apex:pageBlock>
    </apex:form> 

</apex:page>
try Changing your button from a Button to a commandButton and use rerender like this - reRendering the component that contains your other items will also work with actionRegion - I have noticed that the HTML 'button' tag will nullify this behavior and you will get default processing of the form instead. I added a little output text here in my testing that just shows my list count - but this is tested and DOES work.

Hope this helps.

Thanks,
Nagendra
 

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Ravi,

If you use an action region - you can not need to process these validations that are required when adding a new row here like so:
<apex:page standardController="Account" extensions="DynamicTextBox"> 

    <apex:form id="form"> 
        <apex:pageBlock id="block" mode="mainDetail">
           <apex:pageblockSection columns="1">
                <apex:inputField value="{!Account.AccountNumber}" required="true"/>  
             </apex:pageBlockSection>
             <apex:outputPanel id="Outpanel" > 
                  <apex:actionRegion>             
                    <apex:repeat value="{!lstuser}" Var="Auser" id="samrr"> 
                        <apex:inputtext value="{!Auser.name}" styleClass="form-control"/>
                    </apex:repeat>
                    <apex:commandButton value="+" action="{!addName}" reRender="block"   />
                 </apex:actionRegion><br />
                 <apex:outputText value="List size: {!lstUser.size}" />
            </apex:outputPanel> 
        </apex:pageBlock>
    </apex:form> 

</apex:page>
try Changing your button from a Button to a commandButton and use rerender like this - reRendering the component that contains your other items will also work with actionRegion - I have noticed that the HTML 'button' tag will nullify this behavior and you will get default processing of the form instead. I added a little output text here in my testing that just shows my list count - but this is tested and DOES work.

Hope this helps.

Thanks,
Nagendra
 
This was selected as the best answer
Ravi KRavi K
Thanks Nagendra. command button with Action region is working fine.