+ Start a Discussion
Jyothsna ReddyJyothsna Reddy 

Problem facing with SelectList values

Hello everyone.

I am struggling with this problem Please anyone try to help me............
Have a glance on code.
Here I have two records having m.Fieldtype as Combo.so 2 times getItems() will be called right?
So, options (returntype of getItems()) will store 2nd time value .And these values will be displayed in two SelectList values

( I want both values should be different)
How can i get this..?

Visualforce Code
<apex:selectList value="{!inputFields[m.Id]}" size="1" rendered="{!if(m.FieldType__c == 'Combo'  ,true,false)}" >
      <apex:selectoptions value="{!items}" ></apex:selectoptions>
</apex:selectList>

Controller Code:
   public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        comStr=null;
        for(Mapping__c map1:keylist){
            if(map1.FieldType__c=='Combo'){
                 comStr= map1.FieldValue__c;   
                 System.debug('comStr value is::::::::::'+comstr);
            } 
           }
        strList1=comStr.split(',');
        for(String str1:strList1){
            options.add(new SelectOption(str1,str1));
        }
        return options;
    }


Dev.AshishDev.Ashish
Jyothsna,
It is not clear what are you trying to achieve here.. could you describe more? or provide full code?
Jyothsna ReddyJyothsna Reddy
Yes Please check below code,

VisualforceCode:
<apex:page controller="XXForm" showheader="false">
  <apex:form id="thefrm">
    <apex:pageBlock id="box" title="Employee Form" >
    <apex:pagemessages id="showMsg" ></apex:pagemessages>
       <apex:repeat value="{!keylist}" var="m">
          
          <apex:outputLabel value="{!if(m.FieldType__c == 'Combo' ,m.FieldCaption__c,'')}"></apex:outputLabel>
          <apex:outputLabel value="{!if(m.FieldType__c == 'Combo'  && m.Required__c==true,'l','')}" style="color:red;font-size:150%"></apex:outputLabel>    
          <apex:selectList value="{!inputFields[m.Id]}" size="1" rendered="{!if(m.FieldType__c == 'Combo' ,true,false)}" >
              <apex:selectoptions value="{!items}" ></apex:selectoptions>
          </apex:selectList>
            
          </apex:repeat>
       </apex:pageBlock>
       <apex:commandButton value="Save" action="{!mySave}" rerender="thefrm" />
    </apex:form>
</apex:page>

Controller Code:
public with sharing class XXForm {
    public String comStr {get;set;}
    public Map<Id,String> inputFields { get; set; }
    public list<mapping__c> keylist { get; set; }
    public list<string> strlist { get; set; }
    public void data(){
        keylist = new list<mapping__c>();
        inputfields = new  Map<Id,String>();    
        strlist = new list<string>();
       
        keylist = [select FieldCaption__c,FieldName__c,FieldType__c,Required__c,FieldValue__c FROM Mapping__c];
        for(Mapping__c map1:keyList){          
           inputFields.put(map1.Id,'');         
       }
    }
    public XXFormBuildCombo(){
		data();
	}

    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        comStr=null;
        for(Mapping__c map1:keylist){
            if(map1.FieldType__c=='Combo'){
                comStr= map1.FieldValue__c;   
                 System.debug('comStr value is::::::::::'+comstr);
            } 
        }
        strList1=comStr.split(',');
        for(String str1:strList1){
            options.add(new SelectOption(str1,str1));
        }
        return options;
    }

}

 
Here I am building the form dynamically...
I have MappingObject -----> Fields are::::::::::::::FieldName__c,FieldCaption__c && FieldType__c etc----
Records are
FieldName           FieldCaption           FieldType        FieldValue
_____________________________________________________
Status                  Status                            Combo      Active,In-Active
gender                 Gender                          Combo       Male,Female


Here I am trying to  get the  records based on FieldType__c(like ::::combo).

Here I have two records having m.Fieldtype as Combo.so 2 times getItems() will be called right?
So, options (returntype of getItems()) will store 2nd time value .And these values will be displayed in two SelectList values

( I want both values should be different)
Is this possible? If not is there any other way to acheive this?
Did u got this now?
Jyothsna ReddyJyothsna Reddy
Small correction in above code
Here Constructor is XXForm not XXFormBuildCombo (line no:16)
Dev.AshishDev.Ashish
I believe you want to have 2 picklist containing FieldValue corresponds to  2 records having FieldName as Status and Gender respectively.


In this case you have to first create 2 piclist in VF page like below.
<apex:selectList value="{!inputFields[m.Id]}" size="1" rendered="{!if(m.FieldType__c == 'Combo' ,true,false)}" >
10
              <apex:selectoptions value="{!items.pickList1}" ></apex:selectoptions>
11
          </apex:selectList>

          <apex:selectList value="{!inputFields[m.Id]}" size="1" rendered="{!if(m.FieldType__c == 'Combo' ,true,false)}" >
10
              <apex:selectoptions value="{!items.pickList2}" ></apex:selectoptions>
11
          </apex:selectList>

Note: pickList1 and pickList2

Now in controller you have to return List<List<SelectOptions> like 
public List<List<SelectOption>> getItems() {

in getItems method prepare values for pickList1 and pickList2 .

Please try and let us know.

Jyothsna ReddyJyothsna Reddy
Thanq for replying ..
Basically I am not gettting Items.Picklist1...
But here I dont want to hardcode items.picklist1 & items.picklist2.

As of now I am getting only 2 records (i.e., status,gender) but in future it may increase..So I cant hardcode ....


Dev.AshishDev.Ashish
what error you are facing?... if you dont want to hardcode you can use indexes.
Jyothsna ReddyJyothsna Reddy
Hi  Dev Ashish...,
Here I want to assign  values for picklist1and picklist2 in Controller..
But I am getting error
Error: Unknown property 'VisualforceArrayList.pickList1' 

Please help me how to fix this?