You need to sign in to do that
Don't have an account?
Binding a list of apex objects to controller using apex:pageBlockSection
I have a custom visualforce page that looks like this:
Basically, it's a list of identifiers for an account (this is embedded on the account page). Everything behaves as I expect, I can add and remove rows, and when I click "edit" the input fields become active so the data can be modified and the "Edit" changes to "Ok". When I click "Ok" I want the data to be changed and the view to be refreshed with the updated data. However, when I do this, say, changing "12345" to "11111" I click OK and the data reverts back to what it was. I'm not exaclty sure what is going on. Any help would be appreciated. Code is below for reference.
Visualforce Page:
<apex:page standardController="Account" extensions="LegalIdController"> <apex:form> <apex:pageBlock title="Manage Legal Ids"> <apex:outputPanel id="accountHead"> <apex:variable value="{!0}" var="rowNum"/> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!legalIdRowList}" var="legalIdRow" > <apex:column headerValue="Id Type"> <apex:inputText value="{!legalIdRow['legalIdType']}" disabled="{!NOT(legalIdRow['doEdit'])}"/> </apex:column> <apex:column headerValue="Id Value"> <apex:inputText value="{!legalIdRow['legalIdValue']}" disabled="{!NOT(legalIdRow['doEdit'])}"/> </apex:column> <apex:column headerValue="Action"> <apex:commandLink value="Edit" style="color:red" action="{!allowEditForLidRow}" rendered="{!NOT(legalIdRow['doEdit'])}" rerender="accountHead" immediate="true" > <apex:param value="{!rowNum}" name="rowToModify" assignTo="{!rowToModify}"/> </apex:commandLink> <apex:commandLink value="Ok" style="color:red" action="{!disAllowEditForLidRow}" rendered="{!legalIdRow['doEdit']}" rerender="accountHead" immediate="true" > <apex:param value="{!rowNum}" name="rowToModify" assignTo="{!rowToModify}"/> </apex:commandLink> | <apex:commandLink value="Remove" style="color:red" action="{!removeRowFromLidList}" rendered="{!rowNum >= 0}" rerender="accountHead" immediate="true" > <apex:param value="{!rowNum}" name="rowToModify" assignTo="{!rowToModify}"/> </apex:commandLink> <apex:variable var="rowNum" value="{!rowNum + 1}"/> </apex:column> </apex:pageBlockTable> <apex:commandButton action="{!addNewRowToLidRowList}" value="New Row"/> </apex:pageBlockSection> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public class LegalIdController { public Integer rowToModify {get;set;} public String modifiedLidType {get;set;} public String modifiedLidValue {get;set;} Account account; public LegalIdController(ApexPages.StandardController acon) { account = ( Account ) acon.getRecord(); } public void removeRowFromLidList() { legalIdRowList.remove(rowToModify); } public void allowEditForLidRow() { legalIdRowList.get(rowToModify).doEdit = true; } public PageReference disAllowEditForLidRow() { System.debug('INSIDE disAllowEditForLidRow()'); System.debug(JSON.serialize(legalIdRowList)); legalIdRowList = legalIdRowList; return null; } public void addNewRowToLidRowList() { LegalIdRow legalIdRow = new LegalIdRow(); legalIdRow.doEdit = true; legalIdRow.legalIdType = ''; legalIdRow.legalIdValue = ''; legalIdRowList.add(legalIdRow); } public List<LegalIdRow> legalIdRowList { get { System.debug('INSIDE getLegalIdRowList()'); if( legalIdRowList == null ) { System.debug('list was null'); legalIdRowList = new List<LegalIdRow>(); Account account = [ SELECT ts_Legal_Identifiers__c FROM Account WHERE Id = :account.Id]; String[] legalIdentifiersForOrg = account.ts_Legal_Identifiers__c.split(';'); if( legalIdentifiersForOrg != null && legalIdentifiersForOrg.size() != 0 ) { for( String legalId : legalIdentifiersForOrg ) { LegalIdRow legalIdRow = new LegalIdRow(); legalIdRow.legalIdType = legalId.split(':').get(0).trim(); legalIdRow.legalIdValue = legalId.split(':').get(1).trim(); legalIdRow.doEdit = false; legalIdRowList.add(legalIdRow); } } } return legalIdRowList; } set; } public without sharing class LegalIdRow{ public Boolean doEdit {get;set;} public String legalIdType {get;set;} public String legalIdValue {get;set;} } }
As an edit, this is the actual disAllowEditForLidRow() method. Not sure if I'm supposed to be doing something with it: