function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
larevolucionlarevolucion 

Last Item in Datatable Fails to Render with Onchange Event

Hello all,

 

I apologize for the obscure subject title but I wasn't sure of a better way to explain this. I'm having an issue I hope someone can assist me with.

 

I have two datatables. The first one allows a user to enter some values and on an "onchange" event, the second table is rerendered to reflect those values. The issue is that the second table does not update when the onchange fires in the last field. Everything works fine when values are entered into any field but the last one

 

I've attached a stripped down version of my code below.

 

Component:

 

<apex:component controller="sampleCon"> <apex:form > <apex:dataTable value="{!Params}" var="paramItems"> <apex:column > <apex:facet name="header">Name</apex:facet> <label >{!paramItems.name}</label> </apex:column> <apex:column > <apex:facet name="header">Value</apex:facet> <apex:actionRegion > <apex:inputText value="{!paramItems.value}"> <apex:actionSupport event="onchange" rerender="reviewRenderPanel"/> </apex:inputText> </apex:actionRegion> </apex:column> </apex:dataTable> </apex:form> <apex:outputPanel id="reviewRenderPanel"> <apex:form > <apex:dataTable value="{!paramValues}" var="paramReview"> <apex:column > <apex:facet name="header">Name</apex:facet> <label >{!paramReview.name}</label> </apex:column> <apex:column > <apex:facet name="header">Value</apex:facet> <label >{!paramReview.value}</label> </apex:column> </apex:dataTable> </apex:form> </apex:outputPanel> </apex:component>

 

Controller:

 

public class sampleCon { List<paramitemswrapper> paramList = new List<paramitemswrapper>(); public List<paramItemswrapper> Params { get { if (paramList.isEmpty()){ paramList.add(new paramitemswrapper('Name1')); paramList.add(new paramitemswrapper('Name2')); paramList.add(new paramitemswrapper('Name3')); } return paramList; } set; } List<paramitemswrapper> paramValueList = new List<paramitemswrapper>(); public List<paramitemswrapper> paramValues { get { if (Params != null) { paramValueList = Params; } return paramValueList; } set; } public class paramitemswrapper { public String name{get; set;} public String value{get; set;} public paramitemswrapper(String paramName) { name = paramName; } } }

 

Any help would be greatly appreciated. Thanks.

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
larevolucionlarevolucion

After messing around with the code some more I found the solution; though I still don't fully understand it. Apparently the "actionRegion" tags needed to surround the entire list, not just the inputText that I was pulling the value from.

 

 

<apex:component controller="sampleCon"> <apex:form > <apex:actionRegion > <apex:dataTable value="{!Params}" var="paramItems"> <apex:column > <apex:facet name="header">Name</apex:facet> <label >{!paramItems.name}</label> </apex:column> <apex:column > <apex:facet name="header">Value</apex:facet> <apex:inputText value="{!paramItems.value}"> <apex:actionSupport event="onchange" rerender="reviewRenderPanel"/> </apex:inputText> </apex:column> </apex:dataTable> </apex:actionRegion> </apex:form> <apex:outputPanel id="reviewRenderPanel"> <apex:form > <apex:dataTable value="{!paramValues}" var="paramReview"> <apex:column > <apex:facet name="header">Name</apex:facet> <label >{!paramReview.name}</label> </apex:column> <apex:column > <apex:facet name="header">Value</apex:facet> <label >{!paramReview.value}</label> </apex:column> </apex:dataTable> </apex:form> </apex:outputPanel> </apex:component>

 

 If anyone has a better explanation on the use of actionRegion I'd appreciate it. Thanks.