+ Start a Discussion
aveforstudy1.3196212890020557Eaveforstudy1.3196212890020557E 

<apex:selectList> getting refreshed and not storing the values.

hi,

i have a pageBlocktable which contains some of the custom fields of  my standard controller, it also contains a pick list which calculates the current year, pervious year and next year.

I need to have a link called "add row" once the user clicks on this link a new row gets added in the table. Everything works fine but the value in the select list (having the year values)  gets refreshed and does not show the selected value.

Has anyone come across this issue.

Any help will be appreciated.

sfdcfoxsfdcfox

You probably neglected to store the value anywhere. Make sure you have a value="{!variable-or-field}" attribute.

 

aveforstudy1.3196212890020557Eaveforstudy1.3196212890020557E

Thanks for the reply.

I have the value attribute already, its still giving issues.

Following is the code snipet:

 

Page

<apex:page standardController="Position__c" extensions="testPage1">
  <apex:form >
      <apex:pageBlock >
      
          <apex:pageBlockTable value="{!pos}" var="p">
              <apex:facet name="footer">
                    <apex:commandLink value="Add Row" action="{!addRow}"/>
                </apex:facet>
              <apex:column headerValue="year">
                  <apex:inputField value="{!p.dynamicList__c}"/>
              </apex:column>
              <apex:column headerValue="Year">
                 <apex:selectList value="{!selecteddate}" size="1">
                     <apex:selectOptions value="{!year}">
                     </apex:selectOptions>
                 </apex:selectList>
              </apex:column>
          </apex:pageBlockTable>
      </apex:pageBlock>
      <apex:outputText >Selected values is {!selectedItem}</apex:outputText>
  </apex:form>
</apex:page>

 

 

Extension:

public with sharing class testPage1 {
    public List<Position__c> pos{get;set;}
    
    public testPage1(ApexPages.StandardController controller) {
        pos = new List<Position__c>();
        pos.add(new Position__c());
    }
    
    public void addRow(){
      pos.add(new Position__c());
      //return pos;  
    }
    public List<SelectOption> getYear(){
        List<SelectOption> year = new List<SelectOption>();
        String LongDate;
        String Currentyear;
        String nextyear;
        String previousyear;  
        DateTime dt = system.Now();
        LongDate = dt.format('EEEE,MMMM,d,yyyy');
        Currentyear=LongDate.substring(16);
        System.debug('LongDate>>>>'+Currentyear);
        Integer CurrentYeartemp = datetime.now().year();
        Integer nextYearTemp = CurrentYeartemp+1;
        Integer previousyearTem =  CurrentYeartemp-1;
        nextyear =String.valueOf(nextYearTemp);
        previousyear=String.valueOf(previousyearTem);
        year.add(new SelectOption(previousyear,previousyear ) );
        year.add(new SelectOption(Currentyear,Currentyear) );
        year.add(new SelectOption(nextyear ,nextyear ) );
        
        return year ;
    }
    public String selecteddate{get;set;}
    public String selectedyear {get;set;}
    public void displayValues(){
      System.debug('selecteddate '+selecteddate);
      selectedyear = selecteddate;
      
    }
    public String selectedItem{get;set;}
}