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
KrishHariKrishHari 

Dynamic binding list variable to dynamic visual force components

I'm using visual force dynamic bindings with the dynamic visual force components and I'm not able to get it work. Here is the situation.

 

Requirement:

  • The user logs in feedback which is a single large text stored in a text area field in a custom object named Feedback. Later, the user can split them into multiple feedbacks and all these multiple feedbacks are stored as child records of the master feedback.

Design: 

I have a visual force page with two output panels: One panel is to display the parent feedback (the 2nd panel is not rendered at this time). The user can edit this text and uses a delimiter (For e.g. '###') to indicate the text to be split into multiple feedbacks and clicks 'Split' button. This posts back to a controller where the 1st panel is set to not to render and the 2nd panel is set to render. The code looks like below:

 

<apex:page controller="MykController1" >
<apex:form>
  <!-- 1st panel -->
  <apex:outputPanel rendered="{!showSplitFeedback">
     <apex:inputtextarea value="{!feedback.Client_Remarks__c}" rows="25" cols="160"> 
<apex:commandButton id="nextConfirmButton" value="Next: Confirm Split" action="{!nextConfirmSplit}" disabled="false" />
</apex:outputPanel> <!-- 2nd panel --> <apex:outputPanel rendered="{!showConfirmSplitFeedback}"> <apex:dynamicComponent componentValue="{!feedbackTabs}"/> </apex:outputPanel> </apex:form>

 

Since the number of child feedbacks is dynamic, I can't have static form, so I went with visual force dynamic components, where I programmatically create the tabs and associate each tab to each of those child feedbacks. Now the user can edit the text in each of these child feedbacks and clicks submit which then should create child feedback records. The problem here is that I'm not able to bind the strings that I split to these text area. Here is the code for the controller. 

 

public class MyController {
  private String delimiter = '###';
  public List<FeedbackWrapper> listFeedbackWrapper;
  public Boolean showSplitFeedback { get; set; }
  public Boolean showConfirmSplitFeedback { get; set; }

  public Component.Apex.TabPanel getFeedbackTabs() {
		listFeedbackWrapper = splitFeedback();
		
		Component.Apex.TabPanel dynTabPanel = new Component.Apex.TabPanel(switchType = 'Ajax', tabClass='activeTab', inactiveTabClass='inactiveTab', value='activeTab');
		Integer index = 0;
		tabCount = listFeedbackWrapper.size();
		for (FeedbackWrapper fbWrapper: listFeedbackWrapper) {
			dynTabPanel.childComponents.add(createChildFeedbackTab(index++, fbWrapper));
		} 
		return dynTabPanel;
  }

  private Component.Apex.Tab createChildFeedbackTab(Integer index, FeedbackWrapper feedbackWrapper) {
		
		Component.Apex.Tab tab = new Component.Apex.Tab(Id = 'tab' + index, Label = 'Feedack' + string.valueOf((index-1)));
		createTabFields(index, tab, feedbackWrapper);
	   	Component.Apex.CommandButton prev = new Component.Apex.CommandButton(value = 'Previous');
	   	tab.childComponents.add(prev);
	    	Component.Apex.CommandButton next = new Component.Apex.CommandButton(value = 'Next');
	    	tab.childComponents.add(next);
		return tab;		    
	}
	
	private List<FeedbackWrapper> splitFeedback() {
		String clientRemarks = feedback.Client_Remarks__c;
		String[] strRemarksList = clientRemarks.split(delimiter, 0);
		listFeedbackWrapper = new List<FeedbackWrapper>();
		for (String remark : strRemarksList) {
			FeedbackWrapper fbWrapper = new FeedbackWrapper(remark);
			listFeedbackWrapper.add(fbWrapper);
		}
		return listFeedbackWrapper; 
	}
	
	private void createTabFields(Integer index, Component.Apex.Tab tab, FeedbackWrapper feedbackWrapper) {
		Component.Apex.PageBlock dynPageBlock = new Component.Apex.PageBlock();
		Component.Apex.PageBlockSection pgBlockSection = new Component.Apex.PageBlockSection(columns=2);
		
		Component.Apex.PageBlockSectionItem pgBlockSectionItem1 = new Component.Apex.PageBlockSectionItem();
		Component.Apex.OutputLabel lblIssueRemarks = new Component.Apex.OutputLabel(Id = tab.Id + 'lblIssueRemarks', value = 'Issue Remarks: ' );
		
		Component.Apex.PageBlockSectionItem pgBlockSectionItem2 = new Component.Apex.PageBlockSectionItem();
		Component.Apex.InputTextArea txtAreaIssueRemarks = new Component.Apex.InputTextArea(Id = tab.Id + 'txtIssueRemarks', cols = 160, rows = 10);
		txtAreaIssueRemarks.expressions.value = '{!getFeedbackWrapperList[index].issueRemarks}';
		
		pgBlockSectionItem1.childComponents.add(lblIssueRemarks);
		pgBlockSectionItem2.childComponents.add(txtAreaIssueRemarks);
		
		pgBlockSection.childComponents.add(pgBlockSectionItem1);
		pgBlockSection.childComponents.add(pgBlockSectionItem2);
		
		dynPageBlock.childComponents.add(pgBlockSection);
		
		tab.childComponents.add(dynPageBlock);
		
	}
   // inner class
   class FeedbackWrapper {
		String title;
		String issueRemarks;
		public FeedbackWrapper(String remark) {
			issueRemarks = remark;
		}
	}
}

 

I have removed some code in order to reduce the clutter.

 

I think I followed as prescribed in this link for dynamic bindings. Another one here.

 

So, how can I bind a list dynamically to a dynamic visual force component? I need to bind it because, I need to get the updated text in the post back in order to save the updated text to the database. Any help is much appreciated.