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
sdbsdb 

Page View State not maintained for dynamically added components?

I have a custom component that wraps some contact fields. What I am finding is that if I manually place the component on my VF page (scenario 1), then when the user clicks submit and a validation error occurs all the data that I typed in is retained when the validation error is shown.

 

However, if I add this component to the page dynamically using the <apex:dynamicComponent> tag (scenario 2),  then when the user clicks submit and a validation error occurs all the data that I previously typed in is lost when the validation error is shown.

 

Example Scenario 1: User enters a value of 'John' for firstName but does not enter a value for lastName. Submit is clicked, required field error is shown, the value of 'John' still appears in the firstName field.

 

Example Scenario 2: User enters a value of 'John' for firstName but does not enter a value for lastName. Submit is clicked, required field error is shown, all fields in the component including firstName have lost their values.

 

Is this to be expected with dynamically added components? Any ideas on what I might be doing wrong here?

 

TIA for any help 

_Prasu__Prasu_

I think this is happening as when you add the component dynamically it is added to a dynamic component part. Whenever it generating the validation rule it is rerendering the whole dynamic compoent and loosing its value. I am not sure if there is any way to avoid that. 

sdbsdb

I got official verification back from Salesforce that this is working 'as designed'. However the lack of view state support for dynamic components really reduces the usefulness of a very powerful feature. Therefore I have created an enhancement request here:

 

https://success.salesforce.com/ideaView?id=08730000000kx6sAAA

 

Please vote for this idea if you are using or would like to use dynamic components!