You need to sign in to do that
Don't have an account?
asadim2
Rerendering loses my values -except the last one!
Controller:
VF page:
Problem 1:
When the commandLink on each row except the last one is clicked, I get a new row but all the input fields reset to their original values. However if I change the value of the last row and click the link on the last row, the value is remembered.
Problem 2:
On click of the link, if I rerender the page instead of pageBlock I don't get a new row. Any ideas why?!
To make it simple you can directly copy/paste above code into your org and test.
public class TestRerenderController { public List<String> titles { get; set; } public List<VO> vos { get; set; } public TestRerenderController() { titles = new String[]{'Title A', 'Title B', ' Title C'}; vos = new List<VO>(); vos.add(new VO('text a')); vos.add(new VO('text b')); vos.add(new VO('text c')); } public void hi() { titles.add('Title D'); vos.add(new VO('text d')); } public class VO { public String text { get; set; } public VO(String s) { text = s; } } }
VF page:
<apex:page controller="TestRerenderController" id="p"> <apex:form id="f"> <apex:pageBlock id="pb"> <apex:variable value="{!-1}" var="index"/> <apex:repeat value="{!titles}" var="title"> <b>{!title}</b><br/> <apex:variable value="{!index+1}" var="index"/> <apex:inputText value="{!vos[index].text}"/><br/> <apex:commandLink action="{!hi}" value="Add D row" reRender="pb"/> <br/><br/> </apex:repeat> </apex:pageBlock> </apex:form> </apex:page>
Problem 1:
When the commandLink on each row except the last one is clicked, I get a new row but all the input fields reset to their original values. However if I change the value of the last row and click the link on the last row, the value is remembered.
Problem 2:
On click of the link, if I rerender the page instead of pageBlock I don't get a new row. Any ideas why?!
To make it simple you can directly copy/paste above code into your org and test.
https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_variable.htm
Note:<apex:variable> does not support reassignment inside of an iteration component, such as <apex:dataTable> or <apex:repeat>. The result of doing so, e.g., incrementing the <apex:variable> as a counter, is unsupported and undefined.
All Answers
Just try below code Page
Yes there is not any error in you code but salesforce getting value in by your way on page.
https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_variable.htm
Note:<apex:variable> does not support reassignment inside of an iteration component, such as <apex:dataTable> or <apex:repeat>. The result of doing so, e.g., incrementing the <apex:variable> as a counter, is unsupported and undefined.