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
babacandoitbabacandoit 

Form values are not getting set from VisualForcePage to the Controller :(

Hi All,

I am trying to save my records, but they are not getting saved :( Tried a lot..
Lost Hope..Please Help me.. 
When ever I click save. Defalt vales are getting saved. NOT the form vales :(

Please some one Help ME..


<!-- VF PAGE -->
<apex:page showHeader="false" applyBodyTag="false" applyHtmlTag="false"
      sidebar="false" docType="html-5.0" standardStylesheets="false"
     controller="setTargetControllerV3">

<body>   
      <apex:form >
        <div class="col-xs-12" style="padding-top:25px;">
            <div class="list-group">
                <div class="list-group-item" style=" Background-color:rgba(0, 138, 255, 0.8);"  >
                    <font color="white" ><center><h3>Set  Targets  For  Sales  Persons</h3></center></font>
                </div>
               
                <div class="list-group-item" style="padding-top: 50px;">
                  
                    <div class="col-sm-2" id="selectYear">
                        <div style="float:left;padding-right: 5px;line-height: 2.5;">
                          <label class="control-label"><b>Select Year</b></label>  </div>
                           
                             <apex:variable var="year" value="{!YEAR(TODAY())}"/>
                                 <div style="float:right">
                                  <select name="year" id="year" class="form-control" >
                                      <option value="{!year}">{!year}</option>
                                      <option value="{!year+1}">{!year+1}</option>
                                      <option value="{!year+2}">{!year+2}</option>
                                  </select>
                                  </div> 
                             </div>
                
                       <center>    
                        <apex:commandButton value="New" action="{!addUser}" styleClass="btn btn-info" rendered="{!renNew}"/>
                        &nbsp;  &nbsp; &nbsp;  &nbsp;                    
                        <apex:commandButton value="Save" action="{!saveUser}" styleClass="btn   btn-success" id="save" rendered="{!renSave}"/>
                        &nbsp;  &nbsp; &nbsp;  &nbsp;                    
                        <apex:commandButton value="Cancel" action="{!cancel}" styleClass="btn   btn-danger" id="cancel" rendered="{!renSave}"/>
                    </center>
                </div>
               
                 <apex:pageBlock id="frm" rendered="{!renSave}">
                    <div class="list-group-item" id="newOrg" style="padding-top:50px">

                        <table class="tg" style="width:100%">
                                      <tr>
                                        <th class="tg-e3zv">SalesPerson</th>
                                        <th class="tg-031e">Year</th>
                                        <th class="tg-e3zv">Target<br/> amount</th>
                                        <th class="tg-e3zv">Same For Months</th>
                                        <th class="tg-e3zv">Jan</th>
                                        <th class="tg-e3zv">Feb</th>
                                        <th class="tg-e3zv">Mar</th>
                                        <th class="tg-e3zv">Apr</th>
                                        <th class="tg-e3zv">May</th>
                                        <th class="tg-e3zv">Jun</th>
                                        <th class="tg-e3zv">Jul</th>
                                        <th class="tg-e3zv">Aug</th>
                                        <th class="tg-e3zv">Sept</th>
                                        <th class="tg-e3zv">Oct</th>
                                        <th class="tg-e3zv">Nov</th>
                                        <th class="tg-e3zv">Dec</th>
                                      </tr>
                                     <apex:variable value="{!0}" var="countRow"/>
                                     <apex:repeat value="{!targetList}" var="tar" >
                                          <apex:variable var="countRow" value="{!countRow+1}"/>
                                      <tr id="ret">
                                        <td class="tg-031e" style=" width:75px;">
                                          
                                              <select name="users" id="{!countRow}" class="form-control" onClick="copyYear(this.id)">
                                                    <option>-None-</option>
                                                    <apex:repeat value="{!userspList}" var="sp">
                                                          <option value="{!target.Sales_Person__c}">{!sp.name}</option>
                                                    </apex:repeat>  
                                               </select>
                                        </td>

                                        <td class="tg-vn4c"><input value="{!tar.Year__c}" id="yr-{!countRow}" style=" width: 75px; height:30px"/> </td>
                                      
                                        <td class="tg-e3zv"><input id="amt-{!countRow}" style=" width: 75px; height:30px"/></td>
                                       
                                        <td class="tg-vn4c">
                                       
                                        <input type="checkbox" name="check1" onchange="copyTextValue(this,this.id)" id="{!countRow}"/>
                                       </td>
                                      
                                        <td class="tg-031e"><input id="p1-{!countRow}" value="{!tar.Jan_Target__c}" style=" width: 75px; height:30px"/></td>
                                        <td class="tg-vn4c"><input value="{!tar.Feb_Target__c}" style=" width: 75px; height:30px" id="p2-{!countRow}"/></td>
                                        <td class="tg-031e"><input value="{!tar.Mar_Target__c}" style=" width: 75px; height:30px" id="p3-{!countRow}"/></td>
                                        <td class="tg-vn4c"><input value="{!tar.Apr_Target__c}" style=" width: 75px; height:30px" id="p4-{!countRow}"/></td>
                                        <td class="tg-031e"><input value="{!tar.May_Target__c}" style=" width: 75px; height:30px" id="p5-{!countRow}"/></td>
                                        <td class="tg-vn4c"><input value="{!tar.Jun_Target__c}" style=" width: 75px; height:30px" id="p6-{!countRow}"/></td>
                                        <td class="tg-031e"><input value="{!tar.Jul_Target__c}" style=" width: 75px; height:30px" id="p7-{!countRow}"/></td>
                                        <td class="tg-vn4c"><input value="{!tar.Aug_Target__c}" style=" width: 75px; height:30px" id="p8-{!countRow}"/></td>
                                        <td class="tg-031e"><input value="{!tar.Sept_Target__c}" style=" width: 75px; height:30px" id="p9-{!countRow}"/></td>
                                        <td class="tg-vn4c"><input value="{!tar.Oct_Target__c}" style=" width: 75px; height:30px" id="p10-{!countRow}"/></td>
                                        <td class="tg-031e"><input value="{!tar.Nov_Target__c}" style=" width: 75px; height:30px" id="p11-{!countRow}"/></td>
                                        <td class="tg-vn4c"><input value="{!tar.Dec_Target__c}" style=" width: 75px; height:30px" id="p12-{!countRow}"/></td>
                                      </tr>
                                      </apex:repeat>
                            </table>
                    </div>
                </apex:pageBlock>
          
             </div>  
            </div>
          </apex:form>

   <!-- Java script starts Here -->
   <script type="text/javascript">
   function copyYear(count){
  
                var actYear = document.getElementById("year").value;
                document.getElementById("yr-"+count).value = actYear;
   }
  
 
</body>                
</apex:page>

<!--VF ENDS-->


/***********Controller**********/
public with sharing class setTargetControllerV3 {


    public List<Target__c> targetList {get;set;}
    public Target__c target {get;set;}
    public List<User> userspList {get;set;}
    public Boolean renNew { get; set; }
    public boolean renSave { get; set; }

   
    public setTargetControllerV3(){
            targetList = new List<Target__c>();
            renNew=true;
            userspList = [Select  u.Name, u.Id From User u where title='SalesPerson'];       
    }
   
    public void addUser() {
      targetList.add(new Target__c());
      renSave =true;
       //System.debug('targetList==>'+targetList[0]);
    }

     public PageReference cancel() {
        return null;
    }

    public PageReference saveUser() {
  
        insert targetList;
        renSave =false;
        return null;
    }
 
}

Cheers
Baba
Thanks in Don

kaustav goswamikaustav goswami
A few points that I noted.

You forgot the closing </script> tag in your VF page posted above.

Please check if the javascript is working correctly. Check if you are getting the dom element correctly using getElementById().

And try and replace the input html elements with <apex:input> tag. On the command button add a renrender attribute and re render the form.

That should help you to know if there are any VF page messages that are getting generated.

Are you able to look into the debug log and see if the method in the controller has been invoked?

Thanks,
Kaustav
AshlekhAshlekh
Hi,

Use rerender="none" tag where you from calling funciton on page.