0

I need to set fields risk1__c, risk2__c, risk3__c to the return value of each of the (3) selectedOption on my visualForce page. I'm using a controller for the option values. How can I set these fields to the selection made on apex:selectOptions value="{!items}"

For example; risk1__c = 1, risk2__c = 4, risk3__c = 4 resulting in an average risk score of 3 (9/3.)

enter image description here

<apex:pageBlockSection columns="2"  showHeader="false" >
    <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Underwriting Audit Risk Score" title="Seasoned UW department, well managed, good controls, good documentation, good pricing decisions vs. inexperienced staff, lack of management controls, poor documentation, unjustified price cutting"/>
    <apex:selectRadio value="{!risk1}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>

   <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Claims Audit Risk Score" title="Claims handling/reserving practices/reserve redundancies or increases or no recent audits impacts uncertainity and reinsurance risk"  />        
    <apex:selectRadio value="{!risk2}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>

    <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Company Financials Risk Score"  title="Consistent profitable results, steady surplus growth, positive AM Best's ratings vs. fluctuating results, flat/declining surplus, negative AM Best's outlook" />
    <apex:selectRadio value="{!risk3}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>

   <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Management Risk Score"  title="Seasoned successful management team with good business plan vs. unproven/struggling management, management turnover, lack of vision for the company" />        
    <apex:selectRadio value="{!risk4}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>                    

    <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Company Growth Risk Score" title="Consistent, planned, manageable growth vs. inconsistent, fluctuating growth, sudden growth in new lines/underperforming lines"  />
    <apex:selectRadio value="{!risk5}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>

   <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Class of business/risk profile Risk Score" title="Regional book of standard lines buiness vs. hazardous classes with severity exposures"  />        
    <apex:selectRadio value="{!risk6}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>

    <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Reinsurance Contract Risk Score" title="Standard wording that clearly states our responsiblilities vs. wording that overly favors the client, few exclusions, vague wording"  />
    <apex:selectRadio value="{!risk7}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>

   <apex:outputText style="text-align:right;font-size:14px;color:blue" value="External exposures Risk Score"  title="Favorable judicial venues, responsive state insurance regulators, good rate change enviornment vs. highly litigious venue, difficult regulators and slow rate change systems" />        
    <apex:selectRadio value="{!risk8}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>        

    <apex:outputText style="text-align:right;font-size:14px;color:blue" value="UW Submission Quality Risk Score" title="Credible, verifiable, quality submission vs. generic, dated, incomplete submission"  />
    <apex:selectRadio value="{!risk9}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>

   <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Reinsurance Partnership Risk Score" title="Good reinsurance partnership is evident including likliehood of payback over time, true long term potential partner, price isn't the only criteria"  />        
    <apex:selectRadio value="{!risk10}" >
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>        



 <apex:outputPanel id="out">             
           <apex:outputPanel >               
            <b><apex:outputText style="text-align:right;font-size:15px;color:black" value="Average Risk Score"/> &nbsp; &nbsp; <apex:outputText style="text-align:right;font-size:14px;color:blue" value="{!averageTotalRisk}"/> </b>              
          </apex:outputPanel> 
 </apex:outputPanel> 

   // CONTROLLER

  public String risk1 {get;set;}  //used for risk assessment 
  public String risk2 {get;set;}  //used for risk assessment  
  public String risk3 {get;set;}  //used for risk assessment 
  public String risk4 {get;set;}  //used for risk assessment   
  public String risk5 {get;set;}  //used for risk assessment 
  public String risk6 {get;set;} //used for risk assessment   
  public String risk7 {get;set;}  //used for risk assessment 
  public String risk8 {get;set;}  //used for risk assessment   
  public String risk9 {get;set;}  //used for risk assessment 
  public String risk10 {get;set;}  //used for risk assessment   
  public String riskAverage = null; ////used for risk assessment 
  public Integer TotalRisk = null;  //used for risk assessment 
  public String averageTotalRisk{get;set;}//store average risk

  public List<SelectOption> getItems() {
   List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('0','No Audit in the Last 3 Years')); 
    options.add(new SelectOption('1','Poor')); 
    options.add(new SelectOption('2','Below Average')); 
    options.add(new SelectOption('3','Average'));         
    options.add(new SelectOption('4','Above Average'));         
    options.add(new SelectOption('5','Superior'));
    return options;
    }

    //calculate the average risk based on the logic
    Public void calculateaverageRisk(){
        if ( (risk1 == null) || (risk2 == null) || (risk3 == null) || (risk4 == null) || (risk5 == null) || (risk6 == null) || (risk7 == null) || (risk8 == null) || (risk9 == null) || (risk10 == null) ) 
        {
         averageTotalRisk = 'Select a score fore every risk.';
        }
        else 
        {
        TotalRisk = ( (integer.valueof(risk1) + integer.valueof(risk2) + integer.valueof(risk3) + integer.valueof(risk4) + integer.valueof(risk5) + integer.valueof(risk6) + integer.valueof(risk7) + integer.valueof(risk8) + integer.valueof(risk9) + integer.valueof(risk10) ));
        averageTotalRisk = string.valueof((TotalRisk/10));
        }
    } 
1
  • Set the selectRadio to either their own properties or directly to the sobject field. Right now they are all set to risk and will overwrite each other Commented Apr 26, 2017 at 4:11

1 Answer 1

1

I think you need change your code a bit, please find the modified code : -

VF page : -

   <apex:pageBlockSection columns="2"  showHeader="false" >
   <apex:outputText style="text-align:right;font-size:14px;color:blue" value="External exposures Risk Score"  title="Favorable judicial venues, responsive state insurance regulators, good rate change enviornment vs. highly litigious venue, difficult regulators and slow rate change systems" />        
    **<apex:selectRadio value="{!risk}" >**//firstone assign for first answer
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>        

    <apex:outputText style="text-align:right;font-size:14px;color:blue" value="UW Submission Quality Risk Score" title="Credible, verifiable, quality submission vs. generic, dated, incomplete submission"  />
    **<apex:selectRadio value="{!risk2}" >**//Second one assign the second answer
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio>

   <apex:outputText style="text-align:right;font-size:14px;color:blue" value="Reinsurance Partnership Risk Score" title="Good reinsurance partnership is evident including likliehood of payback over time, true long term potential partner, price isn't the only criteria"  />        
    **<apex:selectRadio value="{!risk3}" >**////third one assign the third answer
        <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                
        <apex:selectOptions value="{!items}"/>
    </apex:selectRadio> 

     <apex:outputPanel id="out">             
               <apex:outputPanel > 
                 <b>**<apex:outputText style="text-align:right;font-size:15px;color:black" value="Average Risk Score"/> &nbsp; &nbsp; <apex:outputText style="text-align:right;font-size:14px;color:blue" value="{!averageTotalRisk}"/>** </b>//based on selected three values and the calculation average will be calculated

              </apex:outputPanel> 
     </apex:outputPanel> 

</apex:pageBlockSection>

Apex Class : -

    public String risk{get;set;}//assign first risk
    public String risk2{get;set;}//assign second risk
    public String risk3{get;set;}//assign third risk
    **public Integer averageTotalRisk{get;set;}//store average risk**

    public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('0','No Audit in the Last 3 Years')); 
    options.add(new SelectOption('1','Poor')); 
    options.add(new SelectOption('2','Below Average')); 
    options.add(new SelectOption('3','Average'));         
    options.add(new SelectOption('4','Above Average'));         
    options.add(new SelectOption('5','Superior'));
    return options;
}
    //calculate the average risk based on the logic
    Public void calculateaverageRisk(){
        System.debug('1---------'+risk+'---'+risk2+'--'+risk3);
        **if(!String.isEmpty(risk) || !String.isEmpty(risk2) || !String.isEmpty(risk3)){
            averageTotalRisk =Integer.valueOf(risk)+Integer.valueOf(risk2)+Integer.valueOf(risk3); //based on your logic assign some vlues**
            }
    }

your problem is your using same parameter for keeping three different parameter.

3
  • Thanks Avijit ! I've updated the code above which works but looking to enhance the code a bit. Any suggestions on how to shorten the calculateaverageRisk() method? If any of the radio buttons are not selected then I don't want to calculate an average. Tried testing a String or List for any nulls. Also is there a way to sum risk1, risk2,....as TotalRisk instead of taking the valueof for each ? Commented Apr 26, 2017 at 21:31
  • Any suggestions on recent additional question? Commented Apr 27, 2017 at 3:42
  • have updated the code snippet for you above two requirement, hope it solves your purpose. Commented Apr 27, 2017 at 5:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.