What i am simply trying here is to add one blank wrapper object in wrapperList on click of add another
button. Issue is when i set immediate=true
in commandLink
or in actionFunction
, code adds one blank object but other values also get blank,
Simply speaking my previous values which i filled in the form get lost when i hit command link
(When immediate=true
. If immediate=false
it works absolutely fine but i don't want to fire the validation so can't use it.).
Is it the expected behavior or i am doing something wrong? Also what is solution or workaround to keep the values in the form?
Here is the sample code to reproduce issue.
Apex class:
public class TestWrapper{
public List<Wrapper> wrapperObj{get;set;}
Public TestWrapper(){
wrapperObj = new List<Wrapper>();
Wrapper wrapObj = new Wrapper();
wrapObj.index = 1;
wrapperObj.add(wrapObj);
}
public PageReference addAnother(){
Wrapper wrap = new Wrapper();
wrap.index = wrapperObj[wrapperObj.size()-1].index+1;
wrapperObj.add(wrap);
return null;
}
public Class Wrapper{
public String inputStr{get;set;}
public Integer index{get;set;}
}
}
VisualForce Page:
<apex:page controller="TestWrapper" doctype="html-5.0">
<apex:form >
<apex:outputPanel id="outerPanel">
<apex:actionRegion >
<apex:outputPanel id="innerPanel">
<apex:repeat value="{!wrapperObj}" var="obj">
dsadfasdfadsf{!obj.index}
<apex:inputText value="{!obj.inputStr}"/>
<apex:inputHidden value="{!obj.inputStr}"/>
</apex:repeat>
<apex:commandLink value="add another" immediate="true" reRender="outerPanel"
action="{!addAnother}">
</apex:commandLink>
</apex:outputPanel>
</apex:actionRegion>
</apex:outputPanel>
</apex:form>
</apex:page>