8

I am getting above ugly error.How to clean the error without custom error handing in controller.

<apex:page standardController="Account" extensions="EventController"> 
<apex:form >
<apex:pageMessages></apex:pageMessages>
<apex:pageBlock >
<p>
Please select 
</p>
<apex:selectRadio value="{!selectType}" required="true">
 <apex:selectOptions value="{!Option}"/>
</apex:selectRadio>
<apex:commandButton value="Next" action="{!next}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
1
  • A hack, but quick, would be to put an id="thePage" on the apex:page component, then an id="theForm" on the apex:form component, an id="thePageBlock" on the apex:pageBlock component, and finally an id="theRadio" on the apex:selectRadio component. Then the error would display as Error: thePage:theForm:thePageBlock:theRadio: Validation Error: Value is required. Of course you don't have to use the labels as I suggested. Note, if your controller defaulted the value of {!selectType} in its getter method, then the radio button would always have a value and the error could be avoided.
    – cropredy
    Commented Feb 7, 2014 at 22:15

3 Answers 3

9

If you use the label attributed on your selectRadio, that value would be displayed instead of the j-id0.....

    <apex:page standardController="Account" extensions="EventController"> 
<apex:form >
<apex:pageMessages></apex:pageMessages>
<apex:pageBlock >
<p>
Please select 
</p>
<apex:selectRadio value="{!selectType}" label="Choose One" required="true">
 <apex:selectOptions value="{!Option}"/>
</apex:selectRadio>
<apex:commandButton value="Next" action="{!next}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
1
  • The label is key re this error... Commented Feb 7, 2014 at 22:39
2

Each one of the j_id# in the chain represent an Id for an apex tag, if you assign them Ids, then it will show YourIdName:NextIdName:AndSoON

If I use your example and add Ids as so:

<apex:form id="form">
  <apex:pageMessages></apex:pageMessages>
  <apex:pageBlock id="pageBlock">
    <p>Please select </p>
    <apex:selectRadio value="{!selectType}" required="true" id="radioSelectType">
      <apex:selectOptions value="{!Option}"/>
    </apex:selectRadio>
    <apex:commandButton value="Next" action="{!next}" id="buttonNext" />
  </apex:pageBlock>
</apex:form>

The error might be form:pageBlock:radioSelectType and then the error message. As for changing what the error message says, this is only possible (as far as I know) with a controller.

0

To extend @JimRae answer, when using pageBlockSectionItem, the label for the error message can even be different than the value for the "label" portion of the pageBlockSectionItem label-value pair

Example:

<apex:pageBlockSectionItem>
  <apex:outputText value="Please choose an option"/>
  <apex:selectRadio value={!selectType}" required="true" label="option">
    <apex:selectOptions value="{!Option}"/>
  </apex:selectRadio>
</apex:pageBlockSectionItem>

The form will display:

Please choose an option <the radio buttons>

but if no radio option chosen when commandButton clicked, the error message will simply say:

Option : Validation Error : Value is required

omitting the "please etc" pleasantries

You must log in to answer this question.

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