+ Start a Discussion
Derek Patrick DayaDerek Patrick Daya 

Display list of record of my custom object as drop down on VF Page

Hi Eveyone,

I am currently working on an addition requirements and I could not get it to work. Can anyone give me any idea how to achieve below requirement?

Object1 = SMS_Data__c
Object2 = SMS_Data_Template__c

I created a VF page for SMS Data, it has a field called Text_Message__c. Now I added a drop down list on that VF page of all active SMS_Data_Template__c records but for some reason it does not rerender the field.

Here is the suppossedly end result.

SMS_Data__c.Text_Message__c = SMS_Data_Template__c.Text_Message__c;

Please see my codes below:

<!-- Class -->
public SMS_Data_Template__c sdl{get;set;}
public String selectedtemplateId{get;set;}


public List<SelectOption> getListOftemplates(){
           List<SMS_Data_Template__c> TemplateList = [select id,Name,Text_Message__c from SMS_Data_Template__c WHERE Active__c=True] ;
           System.debug('Templates'+TemplateList.size());
           List<SelectOption> TemplateOptionList = new List<SelectOption>();
           TemplateOptionList .add(new SelectOption( ' ' ,'--Select--'));
           for(SMS_Data_Template__c sdl: TemplateList )
           {
                      TemplateOptionList .add(new SelectOption(sdl.id , sdl.Name));
           }
          return TemplateOptionList ;
    }
    public pagereference gettemplate(){
          sdl = [select id,Text_Message__c from SMS_Data_Template__c where id=:selectedtemplateId];
          return null;


<!-- Visualforce Page -->
<apex:pageBlockSectionItem >
<apex:outputlabel value="Select a Template" for="SelectTemplate"/>
<apex:actionRegion >
<apex:selectList value="{!selectedtemplateId}" size="1" multiselect="false" id="SelectTemplate">
<apex:selectOptions value="{!ListOfTemplates}"/>
<apex:actionSupport event="onchange" rerender="Template1" />
 </apex:selectList>
</apex:actionRegion>
</apex:pageBlockSectionItem>

<apex:pageBlockSection columns="1"  collapsible="true" id="Template1" rendered="true">
<apex:inputtextarea rendered="{!sdl<>null}" value="{!sd.Text_Message__c==sdl.Text_Message__c}" style="width: 600px;"/>
<apex:inputtextarea rendered="{!sdl<>null}" value="{!sdl.Text_Message__c}" style="width: 600px;"/>
 </apex:pageBlockSection>

 

Both of the inputtextarea returns null even i have already selected a SMS Data Template record.

 

Thank you in advance to anyone who can point me to the right direction.

Best Answer chosen by Derek Patrick Daya
Alain CabonAlain Cabon
Hello,

You are doing many "strange" things that could not work  ( value="{!sd.Text_Message__c==sdl.Text_Message__c}" ).

gettemplate() is probably not called at all. 

You should copy/paste your complete code because the missing parts are the most important (first lines for example)

Alain

All Answers

Derek Patrick DayaDerek Patrick Daya
I just tried to change the inputtextarea to below but it still did not work:-

<apex:pageBlockSection columns="1"  collapsible="true" id="Template1" rendered="true">
                    <apex:inputtextarea rendered="{!sdl!=null}" value="{!sd.Text_Message__c==sdl.Text_Message__c}" style="width: 600px;"/>
                    <apex:inputtextarea rendered="{!sdl!=null}" value="{!sdl.Text_Message__c}" style="width: 600px;"/>
 <apex:pageBlockSection>
Alain CabonAlain Cabon
Hello,

You are doing many "strange" things that could not work  ( value="{!sd.Text_Message__c==sdl.Text_Message__c}" ).

gettemplate() is probably not called at all. 

You should copy/paste your complete code because the missing parts are the most important (first lines for example)

Alain
This was selected as the best answer
Derek Patrick DayaDerek Patrick Daya

Hi Alain,

Thank you for the response. The id of the template selected was actually captured, but I had to add a new function on the class to pull out a field value on the SMS Data Template and place it on the vf page by rerendering it. Its all okay now.

Thank you so much!

Derek