0

I dont know what i am doing wrong here.

The value to of {!paymentmode} is not getting passed into controller.Everything looks correct.

VF page:

<apex:form >
    <apex:selectList styleClass="form-control input-md" size="1" value="{!PaymentMode}">
        <apex:selectOption itemLabel="--None--" itemvalue="--None--"></apex:selectOption>
        <apex:selectOption itemLabel="Net Banking" itemvalue="Net Banking"></apex:selectOption>
        <apex:selectOption itemLabel="Cheque" itemvalue="Cheque"></apex:selectOption>
        <apex:selectOption itemLabel="Demand Draft" itemvalue="Demand Draft"></apex:selectOption>
    </apex:selectList>
</apex:form>

Apex Class:

Public class AgreementRegistration {
    Public String PolicyName{get;set;}
    Public String PaymentMode{get;set;}
    Public String PremiumType{get;set;}
    Public String PolicyCoverage{get;set;}
}

//Entire code: Pls refer the updated code.So here when i am debugging it in Submit method i am getting null values.Even the value is get set properly.Pls refer only above part in the below code.

<apex:page sidebar="false" showHeader="false" controller="AgreementRegistration">
 <!--<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />-->
  <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.4.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"/>
       <script>
       function Home(){
       window.open('https://c.ap5.visual.force.com/apex/Header1?core.apexpages.request.devconsole=1');
       }
       </script>
   <style>
             .home{
       position: absolute;
       left:20px;
       bottom:90%;
       }
         #background-carousel{
            position:fixed;
            width:100%;
            height:100%;
            z-index:-1;
        }
        .carousel,
        .carousel-inner {
            width:100%;
            height:100%;
            z-index:0;
            overflow:hidden;
        }
     .item {
       background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    font-family: "Roboto", sans-serif;
            width:100%;
            height:100%;
            background-position:center center;
            background-size:cover;
            z-index:0;
        }
    #content-wrapper {
    position:absolute;
    z-index:1 !important;
    min-width:100%;
    min-height:100%;
}
.well {
    opacity:0.95;

}
.title{ color:black; font-size:30px; }
.form-horizontal{
align:center;
}  
       label{

       }

       </style>
       <div class="home">
    <a href="https://c.ap5.visual.force.com/apex/Header2?core.apexpages.request.devconsole=1">
        <apex:image url="{!URLFOR($Resource.StyleSheets,'Styles/home1.png')}" height="40px" width="40px" onclick="Home()">
        </apex:image></a>
    </div>
       <apex:stylesheet value="{!URLFOR($Resource.StyleSheets,'Styles/BootStrap.css')}"/>
        <div id="background-carousel">
         <div id="myCarousel" class="carousel slide" data-ride="carousel">
         <div class="carousel-inner">
          <div class="item" style="background-image:url(https://cdn.websites.hibu.com/cb4a9b02eb4542cc906874fa5577614b/dms3rep/multi/desktop/Slider1_oPXLSXjHR3CKgEOMPGNK-1366x768.jpg )"></div>
         <div class="item active" style="background-image:url(http://ads4access.us/wp-content/uploads/2014/08/Health-Quality3-1366x768.jpg)"></div>
         <div class="item" style="background-image:url(https://us.nttdata.com/en/-/media/nttdataamerica/images/industries/industries-insurance-resized-images/level-1-hero-desktop-insurance-8-1366x768.jpg?h=768&la=en-US&w=1366&hash=C535462BDAE3FCF05E159CC5B3A2641CD1669B45)"></div>
         </div>
         </div>
         </div>
       <div id="content-wrapper">
           <!-- PAGE CONTENT -->
        <div class="container">
        <div class="well"><center><div class="page-header"><p class="title">Enrollment Form</p></div></center></div>
          <center>
             <div class="well">

<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend></legend>
<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="textinput">Policy Name</label>  
  <div class="col-md-3">
      <input id="Name" name="textinput" type="text" placeholder="" value="{!PolicyName}" class="form-control input-md" disabled="true" />

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="textinput">&nbsp;Policy Holder</label>  
  <div class="col-md-3">
      <input id="Name" name="textinput" type="text" value="{!PolicyHolderName}" class="form-control input-md" required="" disabled="true"/>

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="textinput">Premium</label>  
  <div class="col-md-3">
      <input id="textinput" name="textinput" type="text" placeholder="Premium Amount" value="{!Premium}" class="form-control input-md" disabled="true"/>

  </div>
</div>

<!-- Select Basic -->
<div class="form-group">
  <label class="col-md-4 control-label" for="selectbasic">Payment Mode</label>
  <div class="col-md-3">
   <apex:form >
   <apex:selectList styleClass="form-control input-md" size="1" value="{!PaymentMode}">
        <apex:selectOption itemLabel="--None--" itemvalue="--None--"></apex:selectOption>
    <apex:selectOption itemLabel="Net Banking" itemvalue="Net Banking"></apex:selectOption>
     <apex:selectOption itemLabel="Cheque" itemvalue="Cheque"></apex:selectOption>
     <apex:selectOption itemLabel="Demand Draft" itemvalue="Demand draft"></apex:selectOption>
    </apex:selectList> 
     </apex:form>
  </div>
</div>

.
<!-- Select Basic -->
<div class="form-group">
  <label class="col-md-4 control-label" for="" >Premium Type</label>
  <div class="col-md-3">
    <select id="Type" name="" class="form-control" value="{!PremiumType}">
      <option value="">--None--</option>
      <option value="">Flexi</option>
      <option value="">Non Flexi</option>
    </select>
  </div>
</div>

<!-- Select Basic -->
<div class="form-group">
  <label class="col-md-4 control-label" for="selectbasic">Policy Coverage</label>
  <div class="col-md-3">
    <select id="Coverage" name="selectbasic" class="form-control" value="{!PolicyCoverage}">
      <option value="">--None--</option>
      <option value="">Individual</option>
      <option value="">Individual and Spouse</option>
      <option value="">Individual + Spouse + 1Child</option>
    </select>
  </div>
</div>
<!-- Select Basic -->
<div class="form-group">
  <label class="col-md-4 control-label" for="selectbasic">Tenure</label>
  <div class="col-md-3">
    <select id="Tenure" name="selectbasic" class="form-control" value="{!Tenure}">
    <option value="">--None--</option>
      <option value="">One Year</option>
      <option value="">Three years</option>
      <option value="">Five years</option>
      <option value="">Nine years</option>
      <option value="">Fifteen years</option>
    </select>
  </div>
</div>

<!-- Select Basic -->
<div class="form-group">
  <label class="col-md-4 control-label" for="List">Payment Options</label>
  <div class="col-md-3">
    <select id="Options" name="List" class="form-control" value="{!PaymentOptions}">
      <option value="">--None--</option>
      <option value="">One Time</option>
      <option value="">Monthly</option>
      <option value="">Quarterly</option>
      <option value="">Half Yearly</option>
      <option value="">Yearly</option>
    </select>
      <!-- Button -->
  </div>
</div>
      <div class="form-group">
  <label class="col-md-4 control-label" for="singlebutton"></label>
  <div class="col-md-3">
  <p>
  <apex:form >
  <apex:commandButton value="Submit" action="{!Submit}" styleClass="btn btn-warning" />&nbsp;&nbsp;
  <apex:commandButton value="Cancel" action="{!Cancel}" styleClass="btn-primary" />&nbsp;&nbsp;
           </apex:form>

     </p>
  </div>
</div>

</fieldset>
</form>

      </div>
      </center>
      </div>
      </div>

  </apex:page>

Public class AgreementRegistration {
Public String PolicyName{get;set;}
Public String PaymentMode{get;set;}
Public String PremiumType{get;set;}
Public String PolicyCoverage{get;set;}
Public String Tenure{get;set;}
Public String PaymentOptions{get;set;}

Public ID Productid{get;set;}
Public Id PolicyNameId{get;set;}
Public String PolicyHolderName{get;set;}
Public Decimal Premium{get;set;}

    Public AgreementRegistration (){
     PolicyName=ApexPages.currentPage().getParameters().get('key');   
     system.debug(PolicyName); 
     Products__c prod=[Select Premium__c,id from Products__c where Policy_Name__c=:PolicyName][0];
              Premium=prod.Premium__c; 
              Productid=prod.id;
              //User u=[Select Name from User where id='0057F000000S86a'][0];
                // PolicyHolderName=u.Name;
         // Account a=[Select id from Account where name=:u.Name][0]; 
         // PolicyNameId=a.id; 
             Account a=[Select name from Account where id='0017F000007Pbmd'];
             PolicyHolderName=a.name; 
           system.debug(PaymentMode);  
    }


    Public PageReference Submit(){
    system.debug(PaymentMode);
    system.debug(PremiumType);
    Agreement__c ag=new Agreement__c (Policy_Holder__c='0017F000007Pbmd',Contact__c='0037F000007x8pN',Products__c=Productid,
                                       Payment_mode__c=PaymentMode,Payment_Options__c=PaymentOptions,Policy_Coverage__c=PolicyCoverage,
                                      Tenure__c=Tenure, Premium_type__c= PremiumType,Premium__c= Premium,Active__c=true); 
                         insert ag;
                         system.debug(ag);
        return new PageReference('https://c.ap5.visual.force.com/apex/Header2?core.apexpages.request.devconsole=1');      

    }

     Public PageReference Cancel(){
      return new PageReference('https://c.ap5.visual.force.com/apex/Policies?core.apexpages.request.devconsole=1');    
     }

}
1
  • How do you know it's not getting passed to the controller? This code doesn't have any particular way to verify anything (or even call the server). If you're having an issue, it's elsewhere in your code.
    – sfdcfox
    Sep 14, 2017 at 14:32

2 Answers 2

1

You have added two tag within one page.

<apex:form>"
<apex:selectList styleClass="form-control input-md" size="1" value="{!PaymentMode}">
    <apex:selectOption itemLabel="--None--" itemvalue="--None--"></apex:selectOption>
<apex:selectOption itemLabel="Net Banking" itemvalue="Net Banking"></apex:selectOption>
 <apex:selectOption itemLabel="Cheque" itemvalue="Cheque"></apex:selectOption>
 <apex:selectOption itemLabel="Demand Draft" itemvalue="Demand draft"></apex:selectOption>
</apex:selectList> 
 </apex:form>
   <apex:form >
  <apex:commandButton value="Submit" action="{!Submit}" styleClass="btn btn-
 warning" />&nbsp;&nbsp;
  <apex:commandButton value="Cancel" action="{!Cancel}" styleClass="btn-
 primary" />&nbsp;&nbsp;
       </apex:form>

Both this should be in one tag for select list and commandbutton. as data will be submitted for only from a "form" tag of submit button. ( html form basic rule)

Also you need to from html additional "form" tag from your page from your VF page

0
0

There should not be any issue with your code. I tried the following code and get the selected value of dropdown into "PaymentMode"

---------------------VF ------------------------

<apex:page controller="AgreementRegistration">
  <apex:form >
       <apex:selectList styleClass="form-control input-md" size="1" value="{!PaymentMode}">
            <apex:selectOption itemLabel="--None--" itemvalue="--None--"></apex:selectOption>
        <apex:selectOption itemLabel="Net Banking" itemvalue="Net Banking"></apex:selectOption>
         <apex:selectOption itemLabel="Cheque" itemvalue="Cheque"></apex:selectOption>
         <apex:selectOption itemLabel="Demand Draft" itemvalue="Demand Draft"></apex:selectOption>
        </apex:selectList> 
        <br/>
        <apex:commandButton value="Submit" action="{!onSubmit}"/>   
 </apex:form>
</apex:page>

AgreementRegistration class

public class AgreementRegistration {

    Public String PolicyName{get;set;}
    Public String PaymentMode{get;set;}
    Public String PremiumType{get;set;}
    Public String PolicyCoverage{get;set;}
    public pageReference onSubmit(){
        System.debug('---in Submit---' );
        System.debug('The value of payment mode is---> ' + PaymentMode);
        return null;
    }
}

And the debug output is--- 10:34:01:010 USER_DEBUG [11]|DEBUG|---in Submit--- 10:34:01:010 USER_DEBUG [12]|DEBUG|The value of payment mode is---> Cheque

Also it is best practice to use following code instead of hardcoded values in VF page.

reference: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .