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
Oldwen AdrianoOldwen Adriano 

Dynamic Input box value

Hello,

I am creating a dynamic InputText and would like to assign the value as it's created, but I am having trouble getting it to work.
 
public String myval {get;set;} 

custResponseString = custResponse[y].CustomerResponse__c;

 Component.Apex.InputText textAns = new Component.Apex.InputText();       
 textAns.value = custResponseString;  
 myval = custResponseString; 
 textAns.expressions.value = '{!myval}';
 questions.childComponents.add(textAns);

I have included some snippets above which shows my process.  Any help is greatly appreciated.

Thank you,
Oldwen
William TranWilliam Tran

Can you post the whole code and what is the error? what's not working? it does not show up? it shows but does not bind correctly thus not updating correctly? something else?
 

Thx

 

Oldwen AdrianoOldwen Adriano
Entire Sample Code:
 
public with sharing class LeadController
{
    private final Lead ldObj;   
    public List<sObject> vNewLst{get;set;}
    
    id cid;
    public String ans {get; set;}
    public String myval {get;set;}    
    
    public LeadController(ApexPages.StandardController controller)
    {
        //Fetching the Current Lead Record
        this.ldObj = (Lead)controller.getRecord();
    }
    
    public Component.Apex.PageBlock getDynamicDetail() 
    {
        //---------------------------------
        // 1 = Text
        // 2 = Picklist
        // 3 = Multipicklist
        // 4 = Boolean
        //---------------------------------
        
        //  QuestionResponses__c
        
        List<String> ForNothing = new List<String>();
        ForNothing.add('Just for sake of compliences');
        
        
        Lead myLead = [Select Id, Campaign__c from Lead Where Id =: ldObj.Id];
        
        List<Questions__c> relatedQuestions = [Select Id, Campaign__c, Question__c, Type_of_Field__c, Definition_of_Type__c, Order__c from Questions__c Where Campaign__c =: myLead.Campaign__c And Active__c = true Order By Order__c ASC];
        
        List<Available_Answers__c> relatedAnswer = [Select Id, Question_ID__c, Available_Answer__c, Order__c, Active__c from Available_Answers__c Where Question_ID__c in: relatedQuestions Order By Order__c ASC];
        
        //Pull the customer responses.
        List<QuestionResponses__c> custResponse = [SELECT CustomerResponse__c,Id,Lead__c,Name,Questions__c FROM QuestionResponses__c Where Lead__c =: ldObj.Id];
        
        System.debug('Debug Test Here');
        
        Component.Apex.PageBlock output = new Component.Apex.PageBlock ();
        Component.Apex.PageblockTable table = new Component.Apex.PageblockTable();
        table.value = ForNothing;
        table.var = 'genObj';
    
        output.childComponents.add(table);
        
        //--------------------------------------------------------------------------------------
        Component.Apex.Column questions= new Component.Apex.Column();
        questions.headerValue='Questions';
        table.childComponents.add(questions);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
        Component.Apex.Column answers= new Component.Apex.Column();
        answers.headerValue='Answers';
        table.childComponents.add(answers);
        //-------------------------------------------------------------------------------------
        string custResponseString;
        
        for(integer i=0; i < relatedQuestions.size(); i++)
        {
        	custResponseString = '';
        	
        	if(!custResponse.isEmpty())
        	{
        		for(integer y=0; y < custResponse.size(); y++)
		        {
		        	if(relatedQuestions[i].Id == custResponse[y].Questions__c)
		        	{
		        		custResponseString = custResponse[y].CustomerResponse__c;
		        		break;
		        	}
		        }
        	}

            // tr-td start
            Component.Apex.OutputText LineBreakTr1= new Component.Apex.OutputText(value='<tr><td>', escape=false);
            questions.childComponents.add(LineBreakTr1);
            // tr-td start
            
            Component.Apex.outputtext textQues = new Component.Apex.outputtext();
            textQues.value = relatedQuestions[i].Question__c + ' --- ' + custResponseString;
            questions.childComponents.add(textQues);
            
            
            Component.Apex.OutputText LineBreakQA1= new Component.Apex.OutputText(value='</td>', escape=false);
            questions.childComponents.add(LineBreakQA1);
            //------------------------------------------------------------------------
            
            
            System.debug(relatedQuestions[i].Definition_of_Type__c);
            if(relatedQuestions[i].Definition_of_Type__c == 'Text')
            {
                
                Component.Apex.OutputText LineBreakQ11= new Component.Apex.OutputText(value='<td>', escape=false);
                questions.childComponents.add(LineBreakQ11);
            
                Component.Apex.InputText textAns = new Component.Apex.InputText();       
                textAns.value = custResponseString;  
                myval = custResponseString; 
                textAns.expressions.value = '{!myval}';
                questions.childComponents.add(textAns); 
                 
                Component.Apex.OutputText LineBreakQ1= new Component.Apex.OutputText(value='</td>', escape=false);
                questions.childComponents.add(LineBreakQ1);
            }
            else if (relatedQuestions[i].Definition_of_Type__c == 'Picklist')
            {
                Component.Apex.OutputText LineBreakQ12= new Component.Apex.OutputText(value='<td>', escape=false);
                questions.childComponents.add(LineBreakQ12);
                
                Component.Apex.selectList AnswerOptions = new Component.Apex.selectList (size=1);
                
                for(Available_Answers__c AllRelatedAnswers : relatedAnswer)
                {
                    if(AllRelatedAnswers.Question_ID__c  == relatedQuestions[i].id)
                    {
                        Component.Apex.selectOption AnswerOption = new Component.Apex.selectOption();
                        AnswerOption.itemValue = AllRelatedAnswers.Available_Answer__c;
                        AnswerOption.itemLabel = AllRelatedAnswers.Available_Answer__c;
                        AnswerOptions.childcomponents.add(AnswerOption);
                    }
                }
                
                questions.childComponents.add(AnswerOptions );
                
                
                 
                Component.Apex.OutputText LineBreakQ2= new Component.Apex.OutputText(value='</td>', escape=false);
                questions.childComponents.add(LineBreakQ2);
            }
            else if (relatedQuestions[i].Definition_of_Type__c == 'Boolean')
            {
                Component.Apex.OutputText LineBreakQ13= new Component.Apex.OutputText(value='<td>', escape=false);
                questions.childComponents.add(LineBreakQ13);
                
                Component.Apex.Inputcheckbox AnswerOptions = new Component.Apex.Inputcheckbox();
                
                questions.childComponents.add(AnswerOptions);
                
                
                
                Component.Apex.OutputText LineBreakQ3= new Component.Apex.OutputText(value='</td>', escape=false);
                questions.childComponents.add(LineBreakQ3);
            }
            
            
            Component.Apex.OutputText LineBreakQ3= new Component.Apex.OutputText(value='</tr>', escape=false);
            questions.childComponents.add(LineBreakQ3);
        
        }
        
        
            
        return output;
    }
}

Snippet from code above where my issue lies:
 
Component.Apex.InputText textAns = new Component.Apex.InputText();       
                textAns.value = custResponseString;  
                myval = custResponseString; 
                textAns.expressions.value = '{!myval}';
                questions.childComponents.add(textAns);

Now, when my page renders, the text box created above does not have a value inside of the text area.  That is what I am looking to resovle.

Thank you,
Oldwen