0

Not able to show value="{!averageTotalRisk}" on Visualforce page when changing radiobutton options. If all of the radio options are null then I want to show the text 'Select a score for every risk.' once all the radio buttons are selected for each line item then hide the statement and show the calculated value.

<apex:outputPanel id="out">    
<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="{!Account_Summary__c.Average_Risk_Score__c}"/> </b>                                  
<b><apex:outputText style="text-align:right;font-size:15px;color:black" /> &nbsp; &nbsp; <apex:outputText style="text-align:right;font-size:14px;color:blue" value="{!averageTotalRisk}" rendered="{!if(averageTotalRisk=='Select a score fore every risk.','true','false')}" />  </b>           
</apex:outputPanel>      
<br></br> <br></br>  
  <table class="htmlRiskTable">
           <tr valign="center">
              <td> 
              <apex:outputText style="text-align:right;font-size:12px;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"/> 
              </td>
              <td> 
                <apex:selectRadio id="Radio1" value="{!Account_Summary__c.Risk1__c}" style="margin-top: -10px;">
                <apex:actionSupport event="onchange" rerender="out" action="{!calculateaverageRisk}"/>                 
                 <apex:selectOptions value="{!AuditItems}"/>
                </apex:selectRadio>
              </td>
             </tr>

Controller method being called:

public List<SelectOption> getAuditItems() {
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('0', 'No Audit in the Last 3 Years'));
    options.add(new SelectOption('0', 'Poor'));
    options.add(new SelectOption('5', 'Average'));
    options.add(new SelectOption('10', 'Superior'));
    return options;
}

//calculate the average risk based on the logic
Public void calculateaverageRisk() { 
    if ((AccountSummary.Risk1__c == null) || (AccountSummary.Risk2__c == null) || (AccountSummary.Risk3__c == null) || (AccountSummary.Risk4__c == null) || (AccountSummary.Risk5__c == null) || (AccountSummary.Risk6__c == null) || (AccountSummary.Risk7__c == null) || (AccountSummary.Risk8__c == null) || (AccountSummary.Risk9__c == null) || (AccountSummary.Risk10__c == null)) {
        averageTotalRisk = 'Select a score fore every risk.';
    } else { 
        TotalRisk = ((integer.valueof(AccountSummary.Risk1__c) + integer.valueof(AccountSummary.Risk2__c) + integer.valueof(AccountSummary.Risk3__c) + integer.valueof(AccountSummary.Risk4__c) + integer.valueof(AccountSummary.Risk5__c) + integer.valueof(AccountSummary.Risk6__c) + integer.valueof(AccountSummary.Risk7__c) + integer.valueof(AccountSummary.Risk8__c) + integer.valueof(AccountSummary.Risk9__c) + integer.valueof(AccountSummary.Risk10__c)));
        Integer TotalRiskCalc = Integer.valueOf((TotalRisk / 100)*100);
        averageTotalRisk = string.valueof(TotalRiskCalc);
        this.AccountSummary.Average_Risk_Score__c = TotalRiskCalc;
    }
}

When not all radio buttons are selected show this:

enter image description here

When all radio buttons are selected then just show score:

enter image description here

3
  • Why do you need rendered here? You are changing the variable value based on button selection, so it should always display the value you want (either "Select a score" or the score itself). – David Cheng Nov 22 '17 at 21:22
  • How would you suggest I structure value="{!Account_Summary__c.Average_Risk_Score__c} using an IF condition? – rickmac Nov 23 '17 at 2:25
  • Can you post whole VF page code. – NITHESH K Nov 23 '17 at 5:14
1

rendered="{!if(averageTotalRisk=='Select a score fore every risk.','true','false')}"

for showing error line and u need another rendered using not for showing other result thanks

1
  • BINGO! Your suggestion worked. No extra line needed since the text is displayed UNTIL all selections are made. At that time the calculated avg is displayed and the text drops out. Thanks. – rickmac Nov 23 '17 at 20:17
0

Your syntax seems to be wrong. You wrote:

rendered="{ISBLANK({!averageTotalRisk})}"

you needed to write

rendered="{!ISBLANK(averageTotalRisk}}" or even rendered="{!averageTotalRisk == ''}"

Assuming the calculations and rerenders are ok, that should do it.

2
  • Tried both rendering but still nor showing. – rickmac Nov 23 '17 at 0:34
  • Make sure your string is not null at the beginning – Sebastian Kessel Nov 23 '17 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.